gpt4 book ai didi

http - 从 Web.py 中的 PUT 方法获取输入

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:13:47 25 4
gpt4 key购买 nike

我在服务器程序中使用了以下代码:

class AddLibSong:
def PUT(self):
db = MahData.getDBConnection()
songs = json.loads(web.input().to_add)
addToLibrary(songs)
return

但出于某种原因,当我对数据进行 PUT 时:

"to_add=[ { "album" : "Unknonwn", "artist" : "Unknonwn", "host_lib_id" : "1", "is_deleted" :
"false", "server_lib_id" : "-1", "song" : "Moneytalks" } ]"

我收到以下错误:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/web/application.py", line 237, in process
return self.handle()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/web/application.py", line 228, in handle
return self._delegate(fn, self.fvars, args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/web/application.py", line 409, in _delegate
return handle_class(cls)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/web/application.py", line 385, in handle_class
return tocall(*args)
File "/Users/kurtis/sandbox/udj/webserver/Library.py", line 114, in PUT
song = json.loads(web.input().to_add)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/web/utils.py", line 76, in __getattr__
raise AttributeError, k
AttributeError: 'to_add'

127.0.0.1:51096 - - [29/Sep/2011 19:02:58] "HTTP/1.1 PUT /add_songs_to_library" - 500 Internal Server Error

有人知道这是为什么吗?我想我看到了一些关于 Web.py 的内容,如果给定 POST 或 GET,开始只能获取输入,但我在源代码中没有看到任何应该阻止这种情况的内容。

最佳答案

无论如何,如果您想了解有关如何将 PUT 与 WebPy 结合使用的更多详细信息,我会建议您 this很棒的链接。

要使其在最新版本的 webpy 上运行,您应该将“主要”代码更改为:

if __name__ == "__main__":

app=web.application(urls, globals())
app.run()

关于http - 从 Web.py 中的 PUT 方法获取输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7604726/

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