Python Forum

Full Version: [SOLVED] [Debian] UnicodeEncodeError: 'ascii' codec
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Helllo,

I get this error when running a script on a Debian 11 host (Python 3.5.3), apparently because the web site I call through requests() returns UTF8 data:

UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' in position 112: ordinal not in range(128)

In this article, the only thing that works is this:

~# export PYTHONIOENCODING=utf8

How can I make it 1) sticky, and 2) possible to run the script through cron?

Thank you.
After much trial and error, this worked:

~# vi /etc/locale.gen
Uncomment en_US.UTF-8 UTF-8
~# locale-gen


Next:
for item in soup("item"):
        link=item.link.string
        print("<li><a href='{}'>{}</a></li>".format(link,link))