Python 类型错误:';dict';使用request.json()时,对象不可调用
每次我试图通过request.JSON()从请求中获取JSON时,都会出现错误“dict object is not callable”。比如说,Python 类型错误:';dict';使用request.json()时,对象不可调用,python,bottle,Python,Bottle,每次我试图通过request.JSON()从请求中获取JSON时,都会出现错误“dict object is not callable”。比如说, from bottle import run, request, post @post('/') def test(): data = request.json() run(host='localhost',port=8080) 使用curl来测试它 curl -H "Content-Type: application/json" -
from bottle import run, request, post
@post('/')
def test():
data = request.json()
run(host='localhost',port=8080)
使用curl来测试它
curl -H "Content-Type: application/json" -d '{"test":"test"}' -X POST http://localhost:8080/
这是输出
Traceback (most recent call last):
File "C:\Users\javir\AppData\Local\Programs\Python\Python38\lib\site-packages\bottle.py", line 868, in _handle
return route.call(**args)
File "C:\Users\javir\AppData\Local\Programs\Python\Python38\lib\site-packages\bottle.py", line 1748, in wrapper
rv = callback(*a, **ka)
File "d:/Workspace Universidad/SD-P3/test.py", line 5, in test
data = request.json()
TypeError: 'dict' object is not callable
127.0.0.1 - - [12/May/2020 12:43:42] "POST / HTTP/1.1" 500 741
无论内容如何,我总是犯同样的错误。有人知道它可能是什么吗?在python中,当在变量后面包含()
时,会发生“调用”TypeError:“dict”对象不可调用
仅表示request。json
是dict
,无法调用。在request.json
之后删除()
@post('/')
def test():
data = request.json
在python中,如果在变量后面包含()
,则会发生“调用”TypeError:“dict”对象不可调用
仅表示request。json
是dict
,无法调用。在request.json
之后删除()
@post('/')
def test():
data = request.json
它应该是
data=request.json
而不是data=request.json()
它应该是data=request.json
而不是data=request.json()