1
我最近在我的ubuntu機器上下載了webpy,並且目前我的POST函數有問題。 這是我的代碼:Webpy AttributeError'標題鍵'
#! /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
我發送使用鉻應用中的發佈請求:POST-MAN,具有指定鍵,和任意的值。
您使用'data.decider'但似乎'data'沒有財產'decider'。使用'print(data,type(data),dir(data))'來查看'data'中的內容 – furas
@furus我試圖打印出對象的值,並且它是空的:「」,至於鍵入:,並且dir()顯示沒有決定器屬性。我該如何解決這個問題? –
這意味着你發佈的數據錯誤 - 你不會發送任何值。 – furas