Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'encoding': 0.05; 'output': 0.05; '-*-': 0.07; 'sys': 0.07; 'utf-8': 0.07; 'coding:': 0.09; 'interpreted': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'python': 0.11; 'def': 0.12; "'200": 0.16; 'charset': 0.16; 'header:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'specifying': 0.16; 'subject:Unicode': 0.16; 'world!': 0.16; 'wsgi': 0.16; 'comment:': 0.16; 'wrote:': 0.18; 'import': 0.22; 'coding': 0.22; 'header :User-Agent:1': 0.23; 'error': 0.23; 'script': 0.25; 'define': 0.26; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; 'gives': 0.31; "skip:' 10": 0.31; 'subject:with': 0.35; 'display': 0.35; 'but': 0.35; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'browser': 0.61; 'special': 0.74 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Unicode in cgi-script with apache2 Date: Sun, 17 Aug 2014 15:12:30 +0200 Organization: None References: <53f05ed9$0$30003$c3e8da3$5496439d@news.astraweb.com> <53F07892.1030100@ramaekers-stassart.be> <53F099D9.9060005@ramaekers-stassart.be> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: p57bd8432.dip0.t-ipconnect.de User-Agent: KNode/4.13.2 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408281166 news.xs4all.nl 2900 [2001:888:2000:d::a6]:49740 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76427 Dominique Ramaekers wrote: > 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! é ü à ũ That's UTF-8 interpreted as Latin-1. Try specifying the charset in the header: ... response_headers = [('Content-type', 'text/plain; charset=utf-8'), ... > And if I check the encoding with the python script (uncommenting line > #1), I still get ANSI_X3.4-1968