[Tutor] unicode type on cgi script

BRINER Cedric work at infomaniak.ch
Tue Mar 15 10:53:20 CET 2005


python-2.3 apache2
hi,

I'm trying to use unicode function into a cgi script with no success.
#-------- cedric.py---
#!/usr/bin/python
import os,sys
import cgi
import cgitb; cgitb.enable()
print "Content-Type: text/html\
"+os.linesep+"\
"+os.linesep+"<TITLE>hipo'potame</TITLE>"
sys.stdout.flush()
content = u'c\xe9dric'
print content
#---------------------

when I invoke it from my xterm, I get:
> python cedric.py
Content-Type: text/html

<TITLE>hipo'potame</TITLE>
cédric

but the same does not work on apache:


 /home/system/briner/obsadminwww/cedric.py 
    6 "+os.linesep+"\

    7 "+os.linesep+"<TITLE>hipo'potame</TITLE>"

    8 sys.stdout.flush()

    9 content = u'c\xe9dric'

   10 print content

content = u'c\xe9dric'

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
position 1: ordinal not in range(128) 
      args = ('ascii', u'c\xe9dric', 1, 2, 'ordinal not in range(128)') 
      encoding = 'ascii' 
      end = 2 
      object = u'c\xe9dric' 
      reason = 'ordinal not in range(128)' 
      start = 1

As if the stdout as to pbe in ascii??

any idea on how to do this

Cedric BRINER



More information about the Tutor mailing list