This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Py3K can't set the browser's character encoding! (CGI)
Type: enhancement Stage: resolved
Components: Unicode Versions: Python 3.1
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: [PhysiC], ezio.melotti
Priority: normal Keywords:

Created on 2009-07-28 09:42 by [PhysiC], last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg91003 - (view) Author: Hakan ([PhysiC]) Date: 2009-07-28 09:42
I'm new to web programming with Python.
In Python2k, the special "# -*- coding: cp1254 -*-" code sets the
character encoding. It works in the internet browsers too and sets the
browser's character encoding. That was really good. But in Py3k, that
special comment doesn't work. Usually, the encoding is UTF-8 in my
browser. That time, non-ascii Turkish characters seems strange symbols.
The locale.setlocale method doesn't work too. The users must manualy set
the encoding from UTF-8 to Turkish(Windows-1254) or Turkish(ISO-8859-9).
Is there anyway to set browser's encoding with Python 3.1? 
I use IIS7 and Windows 7 x64.
BTW, the ASP don't identify Python. But I can use .py files. So, I did
these thing in CGI/.py
msg91006 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-07-28 13:00
This looks more like a general question than a bug report. You should
probably ask on comp.lang.python or

The "# -*- coding: cp1254 -*-" only specifies the encoding used to save
the source file and it's not related to the encoding used when the data
are printed or sent over the network. This should be the same for both
Py2 and Py3.
The browser determines the encoding reading it from the HTTP headers,
from the content-type in the HTML <meta> tag or from the XML
declaration. If none of these are available it tries to determine it
from the content of the file. You should probably specify the encoding
in the headers and encode the data you send accordingly.

Closing as invalid.
msg91009 - (view) Author: Hakan ([PhysiC]) Date: 2009-07-28 16:52
Thanks for your reply. I said, I'm new to web programming.
Now I add Content-type: text/html; charset=ISO-8859-9...
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50839
2009-07-28 16:52:40[PhysiC]setmessages: + msg91009
2009-07-28 13:00:28ezio.melottisetstatus: open -> closed

nosy: + ezio.melotti
messages: + msg91006

resolution: not a bug
stage: resolved
2009-07-28 09:42:59[PhysiC]create