codecs.StreamRecoder not doing what I expected.
D'Arcy J.M. Cain
darcy at VybeNetworks.com
Sun Dec 13 13:14:12 EST 2015
On Sun, 13 Dec 2015 13:17:24 +0100
Laura Creighton <lac at openend.se> wrote:
> In a message of Sun, 13 Dec 2015 01:35:45 -0500, "D'Arcy J.M. Cain"
> writes:
> >When I try to print it to the web page it fails because the \xe9
> >character is not valid ASCII. However, my default encoding is utf-8.
> >Other web pages on the same server display fine.
> >
> >I have the following in the Apache config by the way.
> >
> >SetEnv PYTHONIOENCODING utf8
> >
> >So, my file is utf-8, I am reading it as utf-8, my Apache server
> >output is set to utf-8. How is ASCII sneaking in?
>
> What is your sys.stdout.encoding ?
>
> just import sys and print the thing.
>
> I think you will find that it is not what you expect.
>
> Laura
>
>>> print(sys.stdout.encoding)
utf8
That's what I was expecting. However when I add that to my web log
output I get this:
get_recipe() PYTHONIOENCODING: None
get_recipe() encoding: 646
Dang! I was sure that I fixed that. I have this in my Apache
configuration:
SetEnv PYTHONIOENCODING utf8
I guess I have an Apache problem now, not a Python one. The strange
thing is that this was a fix for a similar problem I asked about and it
worked. Isn't there some way that I can just set the default encoding
to utf8 for every Python program? Googling suggests that I can't do
that but that doesn't see right.
Since utf8 includes ASCII why wouldn't it be the default anyway?
--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com
More information about the Python-list
mailing list