Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45250

Re: Getting ASCII encoding where unicode wanted under Py3k

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
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; 'args': 0.07; 'differently': 0.07; 'encoded': 0.07; 'subject:Getting': 0.07; 'utf-8': 0.07; 'ascii': 0.09; 'encode': 0.09; 'output,': 0.09; 'posted': 0.15; 'codec': 0.16; 'codecs': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'instead:': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'ordinal': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'script,': 0.16; 'sense,': 0.16; 'skip:| 20': 0.16; 'subject:under': 0.16; 'subject:unicode': 0.16; 'subject:where': 0.16; 'sys.stdout': 0.16; 'which,': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'byte': 0.24; 'values': 0.27; 'header:In-Reply- To:1': 0.27; 'skip:g 30': 0.30; 'code': 0.31; 'getting': 0.31; "skip:' 10": 0.31; 'high.': 0.31; 'run': 0.32; "can't": 0.35; 'case,': 0.35; 'received:84': 0.35; 'but': 0.35; 'doing': 0.36; 'should': 0.36; 'too': 0.37; 'handle': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'most': 0.60; 'skip:t 30': 0.61; 'charset:windows-1252': 0.65; 'header:Reply-To:1': 0.67; 'below.': 0.71; 'reply-to:no real name:2**0': 0.71; 'reply- to:addr:python.org': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=JsTI8qIC c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=7AxPfEIvyrUA:10 a=BJTtfDeAskIA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=N659UExz7-8A:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=0rooyRkZmP4A:10 a=6Hpq2Pnts_tOCiHtJLkA:9 a=pILNOxqGKmIA:10
X-AUTH mrabarnett:2500
Date Mon, 13 May 2013 17:34:15 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5
MIME-Version 1.0
To python-list@python.org
Subject Re: Getting ASCII encoding where unicode wanted under Py3k
References <CAE6_B5TDWrv4riQ27xQ+ENQHV=0ziryagsaXMRgNfwQGxmfDAA@mail.gmail.com>
In-Reply-To <CAE6_B5TDWrv4riQ27xQ+ENQHV=0ziryagsaXMRgNfwQGxmfDAA@mail.gmail.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1632.1368462864.3114.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1368462864 news.xs4all.nl 15913 [2001:888:2000:d::a6]:37149
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45250

Show key headers only | View raw


On 13/05/2013 16:59, Jonathan Hayward wrote:
> I have a Py3k script, pasted below. When I run it I get an error about
> ASCII codecs that can't handle byte values that are too high.
>
> The error that I am getting is:
>
> |UnicodeEncodeError:  'ascii'  codec can't encode character'\u0161' in position 1442: ordinal not in range(128)
>        args = ('ascii', "Content-Type: text/html\n\n<!DOCTYPE html>\n<html>\n...ype='submit'>\n </form>\n </body>\n</html>", 1442, 1443,'ordinalnot  in  range(128)')
>        encoding = 'ascii'
>        end = 1443
>        object = "Content-Type: text/html\n\n<!DOCTYPE html>\n<html>\n...ype='submit'>\n </form>\n </body>\n</html>"
>        reason = 'ordinalnot  in  range(128)'
>        start = 1442
>        with_traceback = <built-in method with_traceback of UnicodeEncodeError object>|
>
> (And that was posted to StackOverflow--one shot in the dark answer so far.)
>
> My code is below. What should I be doing differently to be, in the most
> immediate sense, calls to '''%(foo)s''' % locals()?
>
[snip]
The 'print' functions send its output to sys.stdout, which, in your
case, is set up to encode to ASCII for output, but '\u0161' can't be
encoded to ASCII.

Try encoding to UTF-8 instead:

from codecs import getwriter

sys.stdout = getwriter("utf-8")(sys.stdout.buffer)

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Getting ASCII encoding where unicode wanted under Py3k MRAB <python@mrabarnett.plus.com> - 2013-05-13 17:34 +0100

csiph-web