我在使用CherryPy框架访问http请求的主体时遇到了一些问题。 我在具有Python3和Aptana Web Studio IDE的x86_64 Arch Linux机器上使用CherryPy 3.2.0。cherrypy.request.body.read()error
当我尝试通过平时的cherrypy.request.body.read(),我得到的错误访问请求的身体
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)
导致错误的代码是:
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())
然而,使用
cherrypy.request.body.readline() or cherrypy.request.body.readlines(n)
,而不是
cherrypy.request.body.read()
我可以浏览请求的身体就好了。我试着用Google搜索解决方案,但没有发现。考虑到我是一个总的python新手,必须有一些我做错了,但什么?
在此先感谢您的宝贵帮助。
'print(type(cherrypy.request.body.fp))'给了你什么? (就在'print'行之前。) – jro