Open
Description
EDIT: This was originally entitled "Full example does not work, and I can't figure out why." Digging in, I discovered the reason, as seen in the two following comments.
Code
The code I'm using is here: https://flask-restx.readthedocs.io/en/latest/example.html Copied and pasted it. The only change I made was to run the debug server on 8080.
Repro Steps (if applicable)
- python3 example.py
- Ran
curl http://localhost:8080/todos/
. That printed out the ones already created - Ran
curl http://localhost:8080/todos/ -d "data=Remember the milk" -X POST
Expected Behavior
I expected a Todo to be created
Actual Behavior
127.0.0.1 - - [04/Nov/2020 14:22:29] "GET /todos/ HTTP/1.1" 200 -
[2020-11-04 14:23:31,567] ERROR in app: Exception on /todos/ [POST]
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python3/dist-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python3.8/dist-packages/flask_restx/api.py", line 375, in wrapper
resp = resource(*args, **kwargs)
File "/usr/lib/python3/dist-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/flask_restx/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/flask_restx/marshalling.py", line 248, in wrapper
resp = f(*args, **kwargs)
File "/home/jkugler/app/example.py", line 66, in post
return DAO.create(api.payload), 201
File "/home/jkugler/app/example.py", line 32, in create
todo['id'] = self.counter = self.counter + 1
TypeError: 'NoneType' object does not support item assignment
Debugging uncovered that the data passed to def create(self, data)
was None
which means api.payload here:
def post(self):
'''Create a new task'''
return DAO.create(api.payload), 201
is None
. I have no idea why. I've dumped requeset headers, as well as the contentx of the wsgi.input
object, and everything is there.
Error Messages/Stack Trace
See above.
Environment
- Python version: Python 3.8.6
- Flask version: 1.1.1
- Flask-RESTX version: 0.2.0
- Other installed Flask extensions
Flask-BabelEx 0.9.3
Flask-Compress 1.4.0
Flask-Gravatar 0.4.2
Flask-Login 0.4.1
Flask-Mail 0.9.1
Flask-Migrate 2.5.2
Flask-Paranoid 0.2.0
Flask-Principal 0.4.0
Flask-Security 1.7.5
Flask-SQLAlchemy 2.1
Flask-WTF 0.14.2