gpt4 book ai didi

python - Webpy属性错误 ' header key'

转载 作者:太空宇宙 更新时间:2023-11-03 15:53:11 26 4
gpt4 key购买 nike

我最近在我的 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 "SENT TO INTERFACE"


if __name__ == "__main__":
app = web.application(urls, globals())
app.run()

interface 只是另一个接收 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 使用指定的 key 和任意值发送了 post 请求。

最佳答案

此错误意味着您发送了错误的请求 - 您没有在 POST 中发送 decider

尝试

import requests

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

print(r.text)

关于python - Webpy属性错误 ' header key',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41066139/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com