Re: [Python-es] Error de codificación de texto en C GI

Cesar Ortiz <[email protected]>
Newsgroups gmane.comp.python.general.castellano
Message-ID <[email protected]>
Estas indicando que el texto del archivo es ut8 y estas metiendo texto que
no lo es. Normal que no se vea. Para poner el acento tal tendrías que ver su
encoding en ut8, o cambia el utf8 por latin1.

El 18 de oct de 2009, 10:29 a.m., "Sergio Martín" <[email protected]>
escribió:

Hola.
Estoy intentando hacer una web mediante Python en CGI, utilizo el set de
caracteres UTF-8, toda va bien hasta que meto alguna tilde, pongo un código
de ejemplo:

         #! /usr/local/bin/python3
         # -*- coding: utf_8 -*-

         import cgitb
         cgitb.enable()

         print("Content-Type: text/html; charset=UTF-8")
         print()
         print("Linea sin tilde") # Se ve correctamente
         print("Línea con tilde") # No se ve

Uso python 3.1.1 sobre Mac OS X 10.6.1, el fichero está codificado como
UTF-8, no BOM, y tiene permiso de ejecución.
En el navegador (Safari 4.0.3) solo se ve la primera linea, y si le doy a
"Ver código fuente" sale:

         Linea sin tilde
         <!--: spam
         Content-Type: text/html

         <body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> -->
         <body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> -->
         </font> </font> </font> </script> </object> </blockquote> </pre>
         </table> </table> </table> </table> </table> </font> </font>
</font>

El log del Apache me muestra:

         [Sun Oct 18 10:20:54 2009] [error] [client
fe80::217:f2ff:fee7:9901] Error in sys.excepthook:
         [Sun Oct 18 10:20:54 2009] [error] [client
fe80::217:f2ff:fee7:9901] UnicodeEncodeError: 'ascii' codec can't encode
character '\\xed' in position 1601: ordinal not in range(128)
         [Sun Oct 18 10:20:54 2009] [error] [client
fe80::217:f2ff:fee7:9901]
         [Sun Oct 18 10:20:54 2009] [error] [client
fe80::217:f2ff:fee7:9901] Original exception was:
         [Sun Oct 18 10:20:54 2009] [error] [client
fe80::217:f2ff:fee7:9901] Traceback (most recent call last):
         [Sun Oct 18 10:20:54 2009] [error] [client
fe80::217:f2ff:fee7:9901]   File "/Users/sergio/Sites/python/prueba.py",
line 10, in <module>
         [Sun Oct 18 10:20:54 2009] [error] [client
fe80::217:f2ff:fee7:9901]     print("L\\xednea con tilde") # No se ve
         [Sun Oct 18 10:20:54 2009] [error] [client
fe80::217:f2ff:fee7:9901] UnicodeEncodeError: 'ascii' codec can't encode
character '\\xed' in position 1: ordinal not in range(128)

Si ejecuto el script desde la línea de comandos, el resultado es el
correcto, con tildes.
Y sin usar Python, en un fichero html el resultado también es correcto.
¿Alguna sugerencia?
Gracias._______________________________________________
Lista de correo Python-eshttp://listas.aditel.org/listinfo/python-es
FAQ: http://listas.aditel.org/faqpyes
_______________________________________________
Lista de correo Python-es 
http://listas.aditel.org/listinfo/python-es
FAQ: http://listas.aditel.org/faqpyes
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.