|
David Fraser
davidf at sjsoft.com
Thu Sep 18 22:25:46 EST 2003
Sean Gillies wrote:
> Hi,
>
> I'm running into problems with UnicodeEncodeErrors using
> mod_python-3.0.3 with
> Python 2.3 on OS X. Yes, I know I'm asking for trouble with this
> combination,
> but I'm leery of replacing Apple's Python 2.2 (which doesn't work
> with mod_python).
> All in all, my application is working, but will eventually (and
> unpredictably)
> stop and raise this error:
>
> Mod_python error: "PythonHandler mod_python.publisher"
>
> Traceback (most recent call last):
>
> File
> "/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-
> packages/mod_python/apache.py", line 332, in HandlerDispatch
> result = object(req)
>
> File
> "/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-
> packages/mod_python/publisher.py", line 201, in handler
> result = str(result)
>
> UnicodeEncodeError: 'ascii' codec can't encode character '\u3137' in
> position 412: ordinal not in range(128)
>
> Anybody else using Python 2.3 who has seen this? I really don't
> understand the error,
> it's always '\u3137', and I'm _not_ (to my knowledge) using any
> unicode strings. I am
> using Zope's Page Templates, but I don't see where the page templates
> would be introducing
> '\u3137' (the hangul letter tikeut?!).
>
> My module is published with no problems on Linux (KRUD) with
> mod_python-3.0.1 and
> Python 2.2.3, so I'm presently living with this problem on my
> notebook and counting
> on its absence on the server.
>
> Sean
>
> --
Try doing things like:
if type(result) == unicode:
result = result.encode('iso8859')
You can look up different encodings in the encodings module. The above
works well for me...
I think you should be able to get the browser's desired encodings from
the headers sent to the request.
Hope that helps
David
|