We're using web.py with modwsgi (which I can recommend). We've
recently switched from modpython. As far as I remember, modpython
allowed unicode strings as well as str() strings as headers. However,
modwsgi apparently does not. Try, for example
web.seeother(u"/this/is/a/unicode/url/")
and you'll get an internal server error in your browser, and a
TypeError in your apache log.
I'm not sure whether this is best fixed at the modwsgi level, or at
the web.py level, but I've settled on fixing it at the web.py level as
the easiest immediate solution. Here's a simple patch which fixed it
for me, in case you guys find it useful -- let me know if I've missed
something obvious ;-)
--------------------------------------------------
--- webapi.py (revision 172)
+++ webapi.py (working copy)
@@ -71,7 +71,7 @@
for h, v in ctx.headers:
if h.lower() == hdr.lower(): return
- ctx.headers.append((hdr, value))
+ ctx.headers.append((hdr, str(value)))
def output(string_):
"""Appends `string_` to the response."""
It is a requirement of WSGI specification that only 'string' objects
be provided as either key or value in response headers. See 'Unicode
Issues' in:
http://www.python.org/dev/peps/pep-0333/
I vaguely recollect this issue coming up on this list before.
Graham
Berwyn Hoyt,
Senior Hardware Engineer: ber...@brush.co.nz
Ph: +64 3 359 2101; Mobile: +64 21 045
7830
Brush
Technology: www.brush.co.nz
I think this should be value.encode('utf-8') instead of str(value).