Unicode in cgi-script with apache2

Dominique Ramaekers dominique at ramaekers-stassart.be
Sun Aug 17 08:02:33 EDT 2014


As I suspected, if I check the used encoding in wsgi I get:
ANSI_X3.4-1968

I found you can define the coding of the script with a special comment: 
# -*- coding: utf-8 -*-

Now I don't get an error but my special chars still doesn't display well.
The script:
# -*- coding: utf-8 -*-
import sys
def application(environ, start_response):
     status = '200 OK'
     output = 'Hello World! é ü à ũ'
     #output = sys.getfilesystemencoding() #1

     response_headers = [('Content-type', 'text/plain'),
                         ('Content-Length', str(len(output)))]
     start_response(status, response_headers)

     return [output]

Gives in the browser as output:

Hello World! é ü à ũ

And if I check the encoding with the python script (uncommenting line 
#1), I still get ANSI_X3.4-1968

This is really getting on my nerves.


Op 17-08-14 om 13:04 schreef Peter Otten:
> Dominique Ramaekers wrote:
>
>> Putting the lines in my apache config:
>> AddDefaultCharset UTF-8
>> SetEnv PYTHONIOENCODING utf-8
>>
>> Cleared my brower-cache... No change.....
> Did you restart the apache?
>
>




More information about the Python-list mailing list