POSTing to a page - AssertionError: recv(8192) returned 9655 bytes

76 views
Skip to first unread message

elliott

unread,
Jun 8, 2009, 8:53:10 AM6/8/09
to cherrypy-users
I'm trying to POST XML to my CherryPy server, but I'm getting the
following error:

File "C:\Python25\Lib\site-packages\cherrypy\_cprequest.py", line 617,
in respond
self.process_body()
File "C:\Python25\Lib\site-packages\cherrypy\_cprequest.py", line
739, in process_body
keep_blank_values=1)
File "C:\Python25\lib\site-packages\cherrypy\_cpcgifs.py", line 8,
in __init__
cgi.FieldStorage.__init__(self, *args, **kwds)
File "C:\Python25\lib\cgi.py", line 536, in __init__
self.read_single()
File "C:\Python25\lib\cgi.py", line 666, in read_single
self.read_binary()
File "C:\Python25\lib\cgi.py", line 680, in read_binary
data = self.fp.read(min(todo, self.bufsize))
File "C:\Python25\lib\site-packages\cherrypy\wsgiserver
\__init__.py", line 199, in read
data = self.rfile.read(size)
File "C:\Python25\lib\site-packages\cherrypy\wsgiserver
\__init__.py", line 809, in read
assert n <= left, "recv(%d) returned %d bytes" % (left, n)
AssertionError: recv(8192) returned 9655 bytes

9655 is the Content-Length of my message, the code that I'm using to
POST is:

headers = {'Content-type': 'text/xml',
'SOAPAction' : "",
"Content-Length" : len(xml)}
url = "https://87.84.103.220:7443/soap/"
req = urllib2.Request(url, urllib.quote_plus(xml), headers)
response = urllib2.urlopen(req)
print response
print response.read()

With my CherryPy code as:

class Soap(object):
@cherrypy.expose()
def index(self):
try:
xmlBody = cherrypy.request.body.read()
..

Any ideas?

Robert Brewer

unread,
Jun 8, 2009, 11:01:32 AM6/8/09
to cherrypy-users

elliott wrote:
> AssertionError: recv(8192) returned 9655 bytes
> 9655 is the Content-Length of my message, the code that
> I'm using to POST is:
>
>     headers = {'Content-type': 'text/xml',
>         'SOAPAction' : "",
>         "Content-Length" : len(xml)}
>     url = "https://87.84.103.220:7443/soap/"
>     req = urllib2.Request(url, urllib.quote_plus(xml), headers)

You're sending urllib.quote_plus(xml) as the payload but len(xml) as the Content-Length. Try sending len(urllib.quote_plus(xml)) as the Content-Length instead.


Robert Brewer
fuma...@aminus.org

elliott

unread,
Jun 8, 2009, 11:38:37 AM6/8/09
to cherrypy-users
Same problem, I've also used alternatives such as:

escaped = urllib.quote_plus(xml)
h = httplib2.Http(".cache")
resp, content = h.request(url, "POST", body=escaped, headers={'content-
type':'text/xml'})

With the same outcome.
> fuman...@aminus.org

Eric Larson

unread,
Jun 8, 2009, 12:23:46 PM6/8/09
to cherryp...@googlegroups.com
Hi,

On Mon, Jun 8, 2009 at 10:38 AM, elliott<3ll...@gmail.com> wrote:
>
> Same problem, I've also used alternatives such as:
>
> escaped = urllib.quote_plus(xml)
> h = httplib2.Http(".cache")
> resp, content = h.request(url, "POST", body=escaped, headers={'content-
> type':'text/xml'})
>
> With the same outcome.

If you are posting XML as the body of the request, then why do you
need to quote/escape it? It seems clear there is a mismatch between
the size reported and the actual size, and if you're sending a xml
document as the body of the request, then it doesn't make much sense
escaping/quoting it.

Just something else to try.

--

Eric Larson
Reply all
Reply to author
Forward
0 new messages