Python Webpy AttributeError';标题键';
我最近在我的ubuntu机器上下载了webpy,目前它的POST功能有问题。 这是我的密码:Python Webpy AttributeError';标题键';,python,ubuntu,web.py,Python,Ubuntu,Web.py,我最近在我的ubuntu机器上下载了webpy,目前它的POST功能有问题。 这是我的密码: #! /usr/bin/env python import web,interface urls = ( '/', 'index' ) class index(object): def POST(self): data = web.input() interface.interfaceModule(data.decider) return "
#! /usr/bin/env python
import web,interface
urls = (
'/', 'index'
)
class index(object):
def POST(self):
data = web.input()
interface.interfaceModule(data.decider)
return "SENT TO INTERFACE"
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
接口只是另一个类,它接收POST值,并通过串口将其发送给Arduino
以下是错误输出:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 239, in process
return self.handle()
File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 230, in handle
return self._delegate(fn, self.fvars, args)
File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 462, in _delegate
return handle_class(cls)
File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 438, in handle_class
return tocall(*args)
File "/var/www/cgi-bin/index.py", line 12, in POST
interface.interfaceModule(data.decider)
File "/usr/local/lib/python2.7/dist-packages/web/utils.py", line 76, in _ _getattr__
raise AttributeError, k
AttributeError: 'decider'
192.168.10.1:52225 - - [09/Dec/2016 19:41:09] "HTTP/1.1 POST /" - 500 Internal Server Error
我使用Chromium应用程序:post-MAN发送了post请求,带有指定的键和任意值。此错误意味着您发送了错误的请求-您的post中没有发送决策者 试一试
您使用了
data.decider
,但似乎data
没有属性decider
。使用print(data,type(data),dir(data))
查看data
@furus中的内容我之前尝试打印出对象值,但它是空的:“”,对于type:,dir()不显示decider属性。我该如何解决这个问题?这意味着你发布了错误的数据-你没有发送任何值。谢谢,它成功了!我知道我一直在用PostMan和HttpRequest浏览器插件做错事
import requests
r = requests.post('http://localhost:8080', data={'decider':'Hello World'})
print(r.text)