Modwsgi headers

2 views
Skip to first unread message

Bryan Hoyt

unread,
Jun 26, 2007, 7:28:07 PM6/26/07
to web.py
Hi,

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."""

Graham Dumpleton

unread,
Jun 26, 2007, 9:02:24 PM6/26/07
to web.py

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

unread,
Jun 27, 2007, 4:07:44 PM6/27/07
to we...@googlegroups.com
In that case, Anand, would you think it appropriate to commit the patch below into svn?  Thanks.
--

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

Aaron Swartz

unread,
Jul 5, 2007, 4:45:35 PM7/5/07
to we...@googlegroups.com

Anand

unread,
Jul 9, 2007, 10:42:00 AM7/9/07
to web.py

> 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.
> --------------------------------------------------
>
> --- 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."""

I think this should be value.encode('utf-8') instead of str(value).

Reply all
Reply to author
Forward
0 new messages