Python3 x64 unicode ok, ARMv7 not - python-3.x

When trying to print a test:
print(áéíóú);
In my x64 computer works fine, but on my ARM7 server which also has Python 3 i get:
Traceback (most recent call last):
File "test.py", line 11, in <module>
print("\xe1\xe9\xedo\xfa")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
I'm puzzled. This last error was supposed to happen on Python 2.x as the strings are by default encoded in ASCII, but on 3 they are by default UNICODE. Any tips?

I suspect that your server has an ascii-only screen. Check by separating input and output on differnet lines and see which line raises.
s = "\xe1\xe9\xedo\xfa"
print(s)

Related

Can't print a Full Block in Python 3.5 using a Raspberry pi and a Windows 10 Terminal

Command print(u'\u2588') works well in Python Online Compiler https://repl.it/languages/python3 but not in Raspberry pi through a windows 10 terminal using Putty. Following error appears:
>>> print('\u2588')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character '\u2588' in position 0: ordinal not in range(128)
I would appretiatte if someone could help...
Problem got resolved with a fresh install of Raspbian Buster with Python 3.7.3 (previously I had Python 3.5).
This might have been the root cause...

Python fails to output unicode literals

I'm trying to output unicode symbols from Python 3. The program is a simple one-liner where I'm printing non-ascii literals:
print("íó")
The program is encoded in utf-8.
I'm running this program on two different Windows machines (Windows 7, Windows 10); on each machine I'm running this from both cmd and MinGW.
That works on Windows 10 (both cmd and MinGW).
On Windows 7 the output is decayed to ascii if run from cmd, and Python throws an exception if being run from MinGW:
Traceback (most recent call last): File "test.py", line 4, in
print("\xed\xf3") File "C:\Program Files (x86)\Python36-32\lib\encodings\cp1251.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in
position 0-1: character maps to
What could be the problem? What should be the difference in the machines (the Python and MinGW versions are very close)? What is the difference of Python run from cmd and MinGW that cause the exception?
Machines configurations:
Windows 7; Python 3.6.0; MinGW 2.8.3
Windows 10; Python 3.6.5; MinGW 2.8.5

UnicodeEncodeError: 'charmap' codec can't encode character '\u2010': character maps to <undefined> [duplicate]

This question already has an answer here:
Why doesn't Python recognize my utf-8 encoded source file?
(1 answer)
Closed 6 years ago.
I keep getting UnicodeEncodeError when trying to print a 'Á' that I get from a website requested using selenium in python 3.4.
I already defined at the top of my .py file
# -*- coding: utf-8 -*-
the def is something like this:
from selenium import webdriver
b = webdriver.Firefox()
b.get('http://fisica.uniandes.edu.co/personal/profesores-de-planta')
dataProf = b.find_elements_by_css_selector('td[width="508"]')
for dato in dataProf:
print(datos.text)
and the exception:
Traceback (most recent call last):
File "C:/Users/Andres/Desktop/scrap/scrap.py", line 444, in <module>
dar_p_fisica()
File "C:/Users/Andres/Desktop/scrap/scrap.py", line 390, in dar_p_fisica
print(datos.text) #.encode().decode('ascii', 'ignore')
File "C:\Python34\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2010' in position 173: character maps to <undefined>
thanks in advance
Already figured it out. As it is noted in this answer, the encoding error doesnt come from python, but from the encoding that the console is using. So the way to fix it is to run the command (in windows):
chcp 65001
that sets the encoding to UTF-8 and then run the program again. Or if working on pycharm as I was, go to Settings>Editor>File Encodings and set the IDE and Project encodings accondingly.

python 3.4 encoding in windows 8.1

I use the script mentioned in this question, to check the encoding:
import sys, locale, os
print(sys.stdout.encoding)
print(sys.stdout.isatty())
print(locale.getpreferredencoding())
print(sys.getfilesystemencoding())
print(os.environ["PYTHONIOENCODING"])
print(chr(246), chr(9786), chr(9787))
and I obtain (python 3.4, windows 8.1):
windows-1252
False
cp1252
mbcs
windows-1252
ö Traceback (most recent call last):
File "C:/Users/.../UTF8-comprovacio.py", line 8, in <module>
print(chr(246), chr(9786), chr(9787))
File "C:\Python34\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u263a' in position 0: character maps to <undefined>
I'm trying to change windows 8.1 encoding (e.g. I add an environment variable called "PYTHONIOENCODING" vith utf8 value) but the result is always the same. How can I change the encoding and the value of PYTHONIOENCODING in Windows 8.1? (in fact, I have another computer, also with Windows 8.1, that shows the correct values, utf-8, but I don't know why)
I had the same problem last week... I ended up just changing in IDE. Don't know your IDE, but if PyCharm, starting from the menu bar: File -> Settings... -> Editor -> File Encodings, then set: "IDE Encoding", "Project Encoding" and "Default encoding for properties files" ALL to UTF-8 and she now works like a charm.
Maybe yours has a similar option.

error when installing pyramid_jinja2 on production server

I have no problems with using pip/install pyramid_mongodb on a production server.
However, when it comes to pyramid_jinja2, this problem keeps popping up and it's driving me nuts. I have used pip/install and easy_install, but both doesn't seem to work.
I'm using python3.3
How should I resolve this?
root#vre [/home/vrnet/public_html/env]# sudo -u vrnet ./bin/pip install pyramid_jinja2
Downloading/unpacking pyramid-jinja2
Running setup.py egg_info for package pyramid-jinja2
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/home/vrnet/public_html/env/build/pyramid-jinja2/setup.py", line 21, in <module>
CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()
File "/home/vrnet/public_html/env/lib64/python3.3/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 131: ordinal not in range(128)
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/home/vrnet/public_html/env/build/pyramid-jinja2/setup.py", line 21, in <module>
CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()
File "/home/vrnet/public_html/env/lib64/python3.3/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 131: ordinal not in range(128)
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /home/vrnet/public_html/env/build/pyramid-jinja2
The package changelog has non-ascii characters in the file, breaking the package installation. I've filed a bug report about this.
You'll have to take that up with the developers, or switch to Python 2 or a different template engine instead.

Resources