Every time I try to get the JSON from a request via request.json() the error 'dict object is not callable' occurs. For example,
from bottle import run, request, post
@post('/')
def test():
data = request.json()
run(host='localhost',port=8080)
Using curl to test it,
curl -H "Content-Type: application/json" -d '{"test":"test"}' -X POST http://localhost:8080/
This is the output,
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
I'm always having the same error no matter the content. Does anyone knows what could It be?
In python, a "call" happens when you include a ()
after a variable. TypeError: 'dict' object is not callable
simply means that request.json
is a dict
and cannot be called. Remove the ()
after request.json
.
@post('/')
def test():
data = request.json