New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError on Content_Type when raising HTTPUnsupportedMediaType #345

Closed
lucas03 opened this Issue Jan 29, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@lucas03
Copy link

lucas03 commented Jan 29, 2018

hi,
I am checking content type in middleware, and if it is not application/json, I raise HTTPUnsupportedMediaType exception.

Body template for HTTPUnsupportedMediaType:

body_template_obj = Template('''\
The request media type ${CONTENT_TYPE} is not supported by this server.
<br /><br />
${detail}''')

Traceback:

Traceback (most recent call last):
  File "/project/common/middleware/common.py", line 91, in handle_errors
    return req.get_response(app)
  File "/project/venv/lib/python2.7/site-packages/webob/request.py", line 1327, in send
    application, catch_exc_info=False)
  File "/project/venv/lib/python2.7/site-packages/webob/request.py", line 1291, in call_application
    app_iter = application(self.environ, start_response)
  File "/project/venv/lib/python2.7/site-packages/webob/dec.py", line 145, in __call__
    return resp(environ, start_response)
  File "/project/venv/lib/python2.7/site-packages/webob/dec.py", line 131, in __call__
    resp = self.call_func(req, *args, **self.kwargs)
  File "/project/venv/lib/python2.7/site-packages/webob/dec.py", line 196, in call_func
    return self.func(req, *args, **kwargs)
  File "/project/common/middleware/common.py", line 123, in sqlalchemy_sessions
    res = req.get_response(app)
  File "/project/venv/lib/python2.7/site-packages/webob/request.py", line 1327, in send
    application, catch_exc_info=False)
  File "/project/venv/lib/python2.7/site-packages/webob/request.py", line 1291, in call_application
    app_iter = application(self.environ, start_response)
  File "/project/venv/lib/python2.7/site-packages/webob/dec.py", line 145, in __call__
    return resp(environ, start_response)
  File "/project/venv/lib/python2.7/site-packages/webob/dec.py", line 145, in __call__
    return resp(environ, start_response)
  File "/project/venv/lib/python2.7/site-packages/webob/dec.py", line 145, in __call__
    return resp(environ, start_response)
  File "/project/venv/lib/python2.7/site-packages/webob/dec.py", line 145, in __call__
    return resp(environ, start_response)
  File "/project/venv/lib/python2.7/site-packages/webob/exc.py", line 359, in __call__
    app_iter = self.generate_response(environ, start_response)
  File "/project/venv/lib/python2.7/site-packages/webob/exc.py", line 339, in generate_response
    body = self.html_body(environ)
  File "/project/venv/lib/python2.7/site-packages/webob/exc.py", line 314, in html_body
    body = self._make_body(environ, html_escape)
  File "/project/venv/lib/python2.7/site-packages/webob/exc.py", line 304, in _make_body
    return t_obj.substitute(args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/string.py", line 176, in substitute
    return self.pattern.sub(convert, self.template)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/string.py", line 166, in convert
    val = mapping[named]
KeyError: 'CONTENT_TYPE'

Is that expected and I should not raise that Exception if content type is not set?

@bertjwregeer

This comment has been minimized.

Copy link
Member

bertjwregeer commented Jan 29, 2018

That is not expected I wouldn't think. Let me take a look at this before I cut 1.8 and I will see about getting a fix in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment