UnicodeEncodeError: 'ascii' codec can't encode characters in position 49-51: ordinal not in range(128) ()
IonRoux opened this issue · 12 comments
Locale is en_US.UTF-8, python is 2.6.5
Same problem as the other one posted here, but my locale is set correctly.
It printed 1 wow
user@host:~$ doge
wow
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/doge/core.py", line 396, in main
shibe.print_doge()
File "/usr/local/lib/python2.6/dist-packages/doge/core.py", line 245, in print_doge
sys.stdout.write(line)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 49-51: ordinal not in range(128)
()
wow error: Unknown unicode error.
Interesting. Does it look proper if you just cat
the files in doge/static/
? Are all of the locales from /usr/bin/locale
the same? I assume that doge --no-shibe
runs just fine?
When I cat /doge/static I get this. I assume it is not correct: http://i.imgur.com/nAuxaRc.png
All locales do this
--no-shibe works perfectly. Not sure what is up
much frustrate
No, that's not correct Shibe, haha.
That looks like it's inside of Putty, correct? If so, I think there are special encodings you need to set, and IIRC Putty has some latin-1
locale as default. Could you check?
Same problem, except I'm doing it locally through Konsole.
Python 2.6.8.
Locale is en_US.UTF8.
All of the Shibe look correct.
Changing the locale in putty fixed it when using cat
, but using the doge command still outputs an error. Same as @deathweaselx86 now.
I'm seeing the same issue on CentOS 6.5, connecting from iTerm on my Mac. Works with --no-shibe, but if I cat doge.txt I get the pic with no problem.
[ec2-user@ip-10-232-130-138 ~]$ ls -l /usr/sbin | doge
wow
very matchpathcon
many x
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/doge/core.py", line 396, in main
shibe.print_doge()
File "/usr/lib/python2.6/site-packages/doge/core.py", line 245, in print_doge
sys.stdout.write(line)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 49-51: ordinal not in range(128)
()
wow error: Unknown unicode error. Please report at https://github.com/thiderman/doge/issues and include output from /usr/bin/locale
[ec2-user@ip-10-232-130-138 ~]$ /usr/bin/locale
LANG=en_US.UTF-8
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=
[ec2-user@ip-10-232-130-138 ~]$ echo $TERM
xterm-256color
[ec2-user@ip-10-232-130-138 ~]$
If I run locally on my Mac from the same iTerm, doge works fine. locale on the Mac is:
jblock@athena:/Users/jpb/scratchrepo
☺ git:(label_development_builds_) $ locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=
jblock@athena:/Users/jpb/scratchrepo
☺ git:(label_development_builds_) $ echo $TERM
xterm-256color
jblock@athena:/Users/jpb/scratchrepo
☺ git:(label_development_builds*) $
I'm sorry I've been inactive on this issue. Holidays, and honestly I have no idea what's actually going wrong. All of you seem to have a proper setup. I can't reproduce any of this either.
Can someone experiment with changing the failing line to line.encode('utf-8')
or maybe even line.decode('utf-8')
to see if that makes any difference? It might be that the strings are passed around improperly for some unknown reason.
No worries, its a holiday we understand.
with line.encode
:
File "/usr/local/lib/python2.6/dist-packages/doge/core.py", line 246, in print_doge sys.stdout.write(line)
with line.decode
: Same errot but also another one:
File "/usr/local/lib/python2.6/dist-packages/doge/core.py", line 245, in print_doge line.decode('utf-8') File "/usr/lib/python2.6/encodings/utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeEncodeError: 'ascii' codec can't encode characters in position 29-30: ordinal not in range(128) ()
Not completely familliar with python, but I assume this is what you meant:
def print_doge(self): for line in self.lines: line.decode('utf-8') sys.stdout.write(line) sys.stdout.flush()
where line.decode is on line 246
Strings are immutable in Python, so the .decode()
part needs to be declared to a variable or returned. Remove the line you added and change the sys.stdout.write
line to sys.stdout.write(line.decode('utf-8'))
and try with encode
if decode
doesn't cut it.
Changing it to decode
fails, but changing it to encode
worked perfectly. For anyone that finds this in the future with this issue, here is a screenshot of line 245: http://i.imgur.com/IEAqBlw.png
Works perfectly, few unsupported characters, but I should be able to fix that once I'm on a computer
http://i.imgur.com/AS5GfaV.png
Cool. I'll reopen this and see if I can implement something that works for all cases. Thanks for the investigation and finding a solution! 🐕
Sounds good! Much welcome!