Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Getting ASCII encoding where unicode wanted under Py3k

Reply
Thread Tools

Re: Getting ASCII encoding where unicode wanted under Py3k

 
 
MRAB
Guest
Posts: n/a
 
      05-13-2013
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(12
> 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(12')
> 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(12'
> 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)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Getting ASCII encoding where unicode wanted under Py3k Peter Pearson Python 0 05-13-2013 04:32 PM
Unicode/ascii encoding nightmare Thomas W Python 19 11-08-2006 12:41 AM
URI encoding ASCII, LATIN1 or UNICODE? Fritz Bayer Java 2 04-20-2005 01:19 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 1 07-16-2004 01:12 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 0 07-16-2004 10:00 AM



Advertisments