我正在尝试在我的 python 脚本中获取 POST/GET 数据。 我正在使用 web.py 框架,下面是我的代码:
import web
form = web.input()
mydata = form.mydata
这是我得到的错误输出:
File "script.py", line 22, in <module>
form = web.input()
File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/webapi.py", line 330, in input
out = rawinput(_method)
File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/webapi.py", line 291, in rawinput
e = ctx.env.copy()
AttributeError: 'ThreadedDict' object has no attribute 'env'
(我习惯于在 PHP 中获取这些变量,但不确定为什么我在使用 python 时遇到困难)
请您参考如下方法:
在 web.py 中,您必须为 URL 定义一个类,并在其中定义 GET 和 POST 函数。那么在 URL 类的 POST 函数中你可以设置 form = web.input()。下面是这种结构的一个简单示例。
class Index:
def GET(self):
#Your GET code here...
def POST(self):
input = web.input()
