Crashes if a package's description is not in English
OneOfOne opened this issue · comments
Description
If a package's name or description has unicode characters, aurman crashes.
Expected Behavior
Not Crash.
Current Behavior
Well, it crashes.
Possible Solution
in aurman/utilities.py
line 99:
replace:
print(" {}".format(ret_dict['Description']))
with:
print(" {}".format(ret_dict['Description'].encode('utf-8')))
Steps to Reproduce
➤ aurman -Ss peek
aur/peek 1.3.1-1 (70, 5.963747)
Simple screen recorder with an easy to use interface
aur/cardpeek 0.8.4-1 (6, 0.456978)
A tool to read-only the contents of smartcards
aur/peek-git 1.3.1.r45.g22b9fe0-1 (5, 0.007787)
Simple screen recorder with an easy to use interface (latest development release)
aur/cardpeek-svn 206-1 (4, 0)
A tool to read the contents of smartcards
aur/diod-git 1.0.24.r11.g0ea3fe3-1 (0, 0)
A multi-threaded, user space file server that speeks 9P2000.L
aur/peekvc 0.1-1 (0, 0)
Dumps the the current state of a Linux virtual console
aur/poplines 2.1.1-2 (0, 0)
Tools to pop/peek lines from the head/tail or known position within a given file, and output to stdout. Makes files into queues!
aur/python-poplines 2.1.1-2 (0, 0)
Tools to pop/peek lines from the head/tail or known position within a given file, and output to stdout. Makes files into queues!
aur/python2-poplines 2.1.1-2 (0, 0)
Tools to pop/peek lines from the head/tail or known position within a given file, and output to stdout. Makes files into queues!
aur/readesm-fr 2.4-1 (0, 0)
2018-05-09 00:38:06,072 - main - main - ERROR -
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/aurman/main.py", line 526, in main
process(argv[1:])
File "/usr/lib/python3.6/site-packages/aurman/main.py", line 225, in process
search_and_print(search, installed_system, str(pacman_args), repo, aur)
File "/usr/lib/python3.6/site-packages/aurman/utilities.py", line 99, in search_and_print
print(" {}".format(ret_dict['Description']))
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 94: ordinal not in range(128)
What locale have you set on your system? Do you use Arch or something like Manjaro?
I'm using Arch.
➤ localectl
System Locale: LANG=en_US.utf8
LANGUAGE=en_US
VC Keymap: n/a
X11 Layout: n/a
➤ locale
LANG=en_US.utf8
LC_CTYPE=en_US.utf8
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=
➤ python -V; python -c 'import sys; print(sys.getdefaultencoding(), sys.stdin.encoding, sys.stdout.encoding)'
Python 3.6.5
utf-8 UTF-8 UTF-8
➤ uname -a
Linux Ava 4.16.6-1-ARCH #1 SMP PREEMPT Mon Apr 30 12:30:03 UTC 2018 x86_64 GNU/Linux
I added print(sys.getdefaultencoding(), sys.stdin.encoding, sys.stdout.encoding)
before line 99 in aurman/utilities.py
and I got this:
utf-8 ANSI_X3.4-1968 ANSI_X3.4-1968 <<<<<<<<<<
2018-05-09 15:44:21,221 - main - main - ERROR -
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/aurman/main.py", line 526, in main
process(argv[1:])
File "/usr/lib/python3.6/site-packages/aurman/main.py", line 225, in process
search_and_print(search, installed_system, str(pacman_args), repo, aur)
File "/usr/lib/python3.6/site-packages/aurman/utilities.py", line 100, in search_and_print
print(" {}".format(ret_dict['Description']))
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 94: ordinal not in range(128)
The error has to be on your side, adding
print(sys.getdefaultencoding(), sys.stdin.encoding, sys.stdout.encoding)
before line 99 yields on my pc:
utf-8 UTF-8 UTF-8
May you change your locale to en_US.UTF-8
and try it again? Notice the -
between UTF and the 8
That does actually fix it, thanks.
You're welcome :)
Had similar issue because my locale wasn't set to utf-8 correctly - this helped me diagnose it so thanks!
Had the same issue. Glad this exists to help me fix.
have added an entry to the FAQ in the README reagarding this problem