-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
bottle+cherrypy gives ""TypeError: WSGI response header key 'Content-Length' is not a byte string" #195
Comments
Is Bottle compatible with Python 3.x @defnull? |
According to PEP 3333, all request and response headers and metadata are "native" strings, that is, bytes for Python 2 and unicode for python 3. 'Content-Length' nit being a byte string is not a WSGI error. And yes, Bottle is 3.x and pep-3333 compatible. |
OK I could be wrong here, I've not done a lot of work with Python3 yet, but I've done a bit of digging and it seems that wsgi is passing tuples of for header in response_headers:
out.write(wsgi_to_bytes('%s: %s\r\n' % header)) |
It appears that line 720 is the problem. The call to |
Headers are always converted to native strings (using To quote the PEP:
CherryPy seems to assume byte string as header names and values, which is wrong in my opinion. I'll file a bug report just to make sure. |
Here is the ticket: http://www.cherrypy.org/ticket/1087 I do not know how hard it is to fix this, but I'll try to get a working patch to the cherrypy guys. |
I guess cherrypy changed their ticket control, so that URL returns a 404. Your ticket is here https://bitbucket.org/cherrypy/cherrypy/issue/1087/pep-3333-compliance-unicode-response and looks like it is already solved. I'm not sure if it is already released. |
👏 |
Thanks for the feedback. Fixed upstream -> closed |
for future reference the cherrypy ticket is now here: |
I am not sure if this is a bottle or a cherrypy issue, but anyway
I'm using the following configuration:
Arch Linux with 2.6.32-lts kernel
hardware: i686 Intel(R) Atom(TM) CPU N270 @ 1.60GHz
python 3.2
cherrypy-svn 2567-1
bottle 0.9.5
Both a Bottle and a Cherrypy 'hello world' run fine. But when I try to run Bottle with Cherrypy like this:
from bottle import route, run
@route('/')
def hello():
return 'hello world'
run(server='cherrypy',host='192.168.1.5', port=8080)
I get this error message:
Traceback (most recent call last):
File "/usr/lib/python3.2/site-packages/bottle.py", line 743, in wsgi
start_response(status, response.headerlist)
File "/usr/lib/python3.2/site-packages/cherrypy/wsgiserver/wsgiserver3.py", line 1846, in start_response
raise TypeError("WSGI response header key %r is not a byte string." % k)
TypeError: WSGI response header key 'Content-Length' is not a byte string.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.2/site-packages/cherrypy/wsgiserver/wsgiserver3.py", line 1034, in communicate
req.respond()
File "/usr/lib/python3.2/site-packages/cherrypy/wsgiserver/wsgiserver3.py", line 830, in respond
self.server.gateway(self).respond()
File "/usr/lib/python3.2/site-packages/cherrypy/wsgiserver/wsgiserver3.py", line 1808, in respond
response = self.req.server.wsgi_app(self.env, self.start_response)
File "/usr/lib/python3.2/site-packages/bottle.py", line 759, in call
return self.wsgi(environ, start_response)
File "/usr/lib/python3.2/site-packages/bottle.py", line 755, in wsgi
start_response('500 INTERNAL SERVER ERROR', [('Content-Type', 'text/html')])
File "/usr/lib/python3.2/site-packages/cherrypy/wsgiserver/wsgiserver3.py", line 1830, in start_response
raise AssertionError("WSGI start_response called a second "
AssertionError: WSGI start_response called a second time with no exc_info.
`
The text was updated successfully, but these errors were encountered: