Skip to content
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

Python 2 compatibility with unicode response header keys and wsgiref #1420

Open
mircea3 opened this issue May 10, 2023 · 0 comments
Open

Python 2 compatibility with unicode response header keys and wsgiref #1420

mircea3 opened this issue May 10, 2023 · 0 comments

Comments

@mircea3
Copy link

mircea3 commented May 10, 2023

Example:

from __future__ import unicode_literals

...
response.headers['Cache-Control'] = 'max-age=0'
...

Results in:

Traceback (most recent call last):
  File "bottle.py", line 1134, in wsgi
    start_response(response._wsgi_status_line(), response.headerlist, exc_info)
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 179, in start_response
    assert type(name) is StringType,"Header names must be strings"
AssertionError: Header names must be strings

This is similar to issue #923, including the fix, but applies to the header key, as opposed to the value.

The simple fix previously used for header value:

def _hval(value):
+    value = tonat(value)
     ...

could also be used for the header key:

def _hkey(key):
+   key = tonat(key)
    ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant