Python Forum
[SOLVED] [Debian] UnicodeEncodeError: 'ascii' codec
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] [Debian] UnicodeEncodeError: 'ascii' codec
#1
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.
Reply
#2
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))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 562: ord ctrldan 23 4,826 Apr-24-2023, 03:40 PM
Last Post: ctrldan
  UnicodeEncodeError - Dealing with Japanese Characters fioranosnake 2 2,466 Jul-07-2022, 08:43 PM
Last Post: fioranosnake
  UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in position 14: ordin Armandito 6 2,732 Apr-29-2022, 12:36 PM
Last Post: Armandito
  UnicodeEncodeError caused by print when program runs from Popen SheeppOSU 5 2,929 Jan-13-2022, 08:11 AM
Last Post: SheeppOSU
  [UnicodeEncodeError from smtplib] yoohooos 0 3,391 Sep-25-2021, 04:27 AM
Last Post: yoohooos
  ASCII-Codec in Python3 [SOLVED] AlphaInc 4 6,150 Jul-07-2021, 07:05 PM
Last Post: AlphaInc
  codec for byte transparency Skaperen 7 3,855 Sep-25-2020, 02:20 AM
Last Post: Skaperen
  Run script on startup in Debian with systemd? MrGlasspoole 5 3,668 Jul-12-2020, 11:48 AM
Last Post: MrGlasspoole
  'charmap' codec louis216 4 20,194 Jun-30-2020, 06:25 AM
Last Post: louis216
  Which codec can help me decode the html source? vivekagrey 4 3,191 Jan-10-2020, 09:33 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020