I'm trying to print a Unicode character from Python 3 to the web. In Python I can run:
print("Content-Type: text/html; charset=utf-8\n")
print("\u00EA")
When run from the command line it correctly spits out:
Content-type: text/html; charset=utf-8
ê
But when run from the web as a CGI script under Apache, it throws an error:
UnicodeEncodeError: 'ascii' codec can't encode character '\xea' in position 0: ordinal not in range(128)
Any suggestions on how to get Python 3 to print UTF-8 to the web? Thanks!
Edit: The output of locale
in both my account and www-data
(Apache's account) is:
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=