I'm having some problems accessing http requests' bodies with the CherryPy framework. I'm using CherryPy 3.2.0 on a x86_64 Arch Linux machine w/ Python3 and Aptana Web Studio IDE.
When I try to access a request's body via the usual cherrypy.request.body.read(), i get the error
File "/usr/lib/python3.2/site-packages/cherrypy/_cpreqbody.py", line 450, in read
return self.fp.read(size, fp_out)
TypeError: read() takes at most 2 positional arguments (3 given)
The code causing the error is:
import cherrypy
class Test:
def index(self):
print(cherrypy.request.body.read())
#print(cherrypy.request.body.readline()) <- this works!
return 'HelloWorld'
index.exposed = True
if __name__ == '__main__':
cherrypy.quickstart(Test())
However, using
cherrypy.request.body.readline() or cherrypy.request.body.readlines(n)
instead of
cherrypy.request.body.read()
i can skim through the request's body just fine. I tried googling for a solution but found none. Considering i'm a total python newbie, there must be something i am doing wrong, but what?
Thanks in advance for your precious help.
print(type(cherrypy.request.body.fp))
give you? (Just before theprint
line.) – Wernerwernerite