Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

POSTing JSON without specifying content-type header throws 500 #1

Closed
brannondorsey opened this issue Apr 8, 2019 · 0 comments · Fixed by #45
Closed

POSTing JSON without specifying content-type header throws 500 #1

brannondorsey opened this issue Apr 8, 2019 · 0 comments · Fixed by #45
Labels
bug Something isn't working

Comments

@brannondorsey
Copy link
Member

python model.py
Starting model server at http://0.0.0.0:8000...
curl -H "content-type: application/json" -d '{"some_option": 1}' http://0.0.0.0:8000 # 200 OK
curl -d '{"some_option": 1}' http://0.0.0.0:8000 # 500 server error

POSTing JSON without explicitly setting a Content-Type: application/json causes the request to bomb with the following stack trace.

127.0.0.1 - - [2019-04-08 14:27:14] "POST /setup HTTP/1.1" 200 165 0.001232
[2019-04-08 14:27:25,617] ERROR in app: Exception on /setup [POST]
Traceback (most recent call last):
  File "/Users/brannon/Documents/code/runway/rw_python_sdk/venv/lib/python3.7/site-packages/Flask-1.0.2-py3.7.egg/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/brannon/Documents/code/runway/rw_python_sdk/venv/lib/python3.7/site-packages/Flask-1.0.2-py3.7.egg/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/brannon/Documents/code/runway/rw_python_sdk/venv/lib/python3.7/site-packages/Flask_Cors-3.0.7-py3.7.egg/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/Users/brannon/Documents/code/runway/rw_python_sdk/venv/lib/python3.7/site-packages/Flask-1.0.2-py3.7.egg/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/brannon/Documents/code/runway/rw_python_sdk/venv/lib/python3.7/site-packages/Flask-1.0.2-py3.7.egg/flask/_compat.py", line 35, in reraise
    raise value
  File "/Users/brannon/Documents/code/runway/rw_python_sdk/venv/lib/python3.7/site-packages/Flask-1.0.2-py3.7.egg/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/brannon/Documents/code/runway/rw_python_sdk/venv/lib/python3.7/site-packages/Flask-1.0.2-py3.7.egg/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/brannon/Documents/code/runway/rw_python_sdk/venv/lib/python3.7/site-packages/runway_python-0.0.55-py3.7.egg/runway/model.py", line 44, in setup_route
    self.setup_model(opts)
  File "/Users/brannon/Documents/code/runway/rw_python_sdk/venv/lib/python3.7/site-packages/runway_python-0.0.55-py3.7.egg/runway/model.py", line 152, in setup_model
    if name in opts:
TypeError: argument of type 'NoneType' is not iterable

We should either give a 400 bad request error that describes the request must include this specific content-type header, or we could sniff the payload and if it parses as JSON let it by.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant