2016-12-09 52 views
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,具有指定鍵,和任意的值。

+0

您使用'data.decider'但似乎'data'沒有財產'decider'。使用'print(data,type(data),dir(data))'來查看'data'中的內容 – furas

+0

@furus我試圖打印出對象的值,並且它是空的:「」,至於鍵入:,並且dir()顯示沒有決定器屬性。我該如何解決這個問題? –

+0

這意味着你發佈的數據錯誤 - 你不會發送任何值。 – furas

回答

1

此錯誤表示您發送錯誤的請求 - 您在POST中不發送decider

嘗試

import requests 

r = requests.post('http://localhost:8080', data={'decider':'Hello World'}) 

print(r.text) 
+0

感謝它的工作!我看到我在POST MAN和HttpRequest瀏覽器插件中都做錯了 –