Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45250 > unrolled thread
| Started by | MRAB <python@mrabarnett.plus.com> |
|---|---|
| First post | 2013-05-13 17:34 +0100 |
| Last post | 2013-05-13 17:34 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Getting ASCII encoding where unicode wanted under Py3k MRAB <python@mrabarnett.plus.com> - 2013-05-13 17:34 +0100
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2013-05-13 17:34 +0100 |
| Subject | Re: Getting ASCII encoding where unicode wanted under Py3k |
| Message-ID | <mailman.1632.1368462864.3114.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web