Issue #1177 resolved

Unicode error using documented example in Python 3

Jason R. Coombs
created an issue

In #1176, Roman reports that there is a bytes/string error in the headers handling when trying the example in the Custom Response Headers documentation:

Unrecoverable error in the server.
Traceback (most recent call last):
  File "C:\Data\Bisoft Logistics\dev\python\webapi\venv32\lib\site-packages\cherrypy\_cpwsgi.py", line 169, in trap
    return func(*args, **kwargs)
  File "C:\Data\Bisoft Logistics\dev\python\webapi\venv32\lib\site-packages\cherrypy\_cpwsgi.py", line 96, in __call__
    return self.nextapp(environ, start_response)
  File "C:\Data\Bisoft Logistics\dev\python\webapi\venv32\lib\site-packages\cherrypy\_cpwsgi.py", line 379, in tail
    return self.response_class(environ, start_response, self.cpapp)
  File "C:\Data\Bisoft Logistics\dev\python\webapi\venv32\lib\site-packages\cherrypy\_cpwsgi.py", line 233, in __init__
    raise TypeError("response.header_list key %r is not a byte string." % k)
TypeError: response.header_list key 'foo' is not a byte string.

Comments (1)

  1. Jason R. Coombs reporter

    Extract 'encode_header_items' classmethod from HeaderMap.output. Now another function can prepare a header list the same way _cprequest does in .finalize. Updated customheaders documentation to use the new .encode_header_items to ensure the example doesn't fail on Python 3 with a TypeError. Fixes #1177.

    → <<cset 6ac9f27e1ad0>>

  2. Log in to comment