GoogleCloudPlatform / webapp2

webapp2 is a framework for Google App Engine
https://webapp2.readthedocs.org
Other
141 stars 63 forks source link

webapp incorrectly passes non-utf8 charset header to webob #131

Open mikelambert opened 7 years ago

mikelambert commented 7 years ago

I occasionally get these errors when using webapp2 on GAE:

  File "/env/local/lib/python2.7/site-packages/gunicorn/workers/gthread.py", line 274, in handle
    keepalive = self.handle_request(req, conn)
  File "/env/local/lib/python2.7/site-packages/gunicorn/workers/gthread.py", line 328, in handle_request
    for item in respiter:
  File "/env/local/lib/python2.7/site-packages/webapp2.py", line 1523, in __call__
    with self.request_context_class(self, environ) as (request, response):
  File "/env/local/lib/python2.7/site-packages/webapp2.py", line 1408, in __enter__
    request = self.app.request_class(self.environ)
  File "/env/local/lib/python2.7/site-packages/webapp2.py", line 155, in __init__
    super(Request, self).__init__(environ, *args, **kwargs)
  File "/env/local/lib/python2.7/site-packages/webob/request.py", line 137, in __init__
    "req.decode(charset)``" % charset
DeprecationWarning: You passed charset='iso-8859-1' to the Request constructor. As of WebOb 1.2, if your application needs a non-UTF-8 request charset, please construct the request without a charset or with a charset of 'None',  then use ``req = req.decode(charset)``

I believe it's due to the http client passing a content-type header with charset=, which webapp2 is parsing and passing in to the Request() constructor:

https://github.com/GoogleCloudPlatform/webapp2/blob/master/webapp2.py#L180

It looks like this is only done for non-versioned webob (ie 0.9). Unfortunately, my installation of webob==1.6.1 seems to not have a version, either. My version of webob, however, does raise an error if a non-utf8 charset is passed-in: https://github.com/Pylons/webob/blob/master/src/webob/request.py#L128

So I get errors when the client passes a non-utf8 charset, as webapp2 then passes it all the way through to trigger the error.