[cse491] WSGI and Jinja2 don't like each other

C. Titus Brown ctb at msu.edu
Sat Sep 19 21:06:19 PDT 2009


On Fri, Sep 18, 2009 at 10:10:55PM -0400, Phil Deschaine wrote:
> Titus,
> 
> I didn't know how you want us to do part 5 of the homework.. with a normal
> CGI or WSGI.  I guessed the latter, but when I integrate them, i get the
> following error:
> 
> Traceback (most recent call last):
>   File "/opt/lib/python2.5/wsgiref/handlers.py", line 93, in run
>     self.finish_response()
>   File "/opt/lib/python2.5/wsgiref/handlers.py", line 134, in
> finish_response
>     self.write(data)
>   File "/opt/lib/python2.5/wsgiref/handlers.py", line 209, in write
>     assert type(data) is StringType,"write() argument must be string"
> AssertionError: write() argument must be string
> 
> I found this related problem on google:
> http://code.djangoproject.com/ticket/6063
> 
> I know it's django but it's the exact same error.
> 
> Basically, can you help me?

The short answer is that you don't need to integrate it with either --
#5 just says "write the function".  Sneaky of me, I know.

If you insist on doing more work than I require, you can fix this
problem by calling 'str' explicitly on the result of the jinja2 'render'
function, e.g.

	html = str(template.render(locals())

This does however run into problems with weird characters that cannot be
easily translated into string types; think Unicode.  More on that down
the road.

I *knew* I was a genius for not asking you to integrate Jinja2 with the
WSGI server just yet ;).

--titus
-- 
C. Titus Brown, ctb at msu.edu



More information about the cse491-fall-2009 mailing list