Encoding problem in python

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Mar 4 11:18:33 CET 2013

On Mon, 04 Mar 2013 01:37:42 -0800, yomnasalah91 wrote:

> I have a problem with encoding in python 27 shell.
> when i write this in the python shell:
> w=u'العربى'
> It gives me the following error:
> Unsupported characters in input
> any help?

Firstly, please show the COMPLETE error, including the full traceback. 
Python errors look like (for example):

py> x = ord(100)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ord() expected string of length 1, but int found

Copy and paste the complete traceback.

Secondly, please describe your environment:

- What operating system and version are you using? Linux, Windows, Mac 
OS, something else? Which version or distro?

- Which console or terminal application? E.g. cmd.exe (Windows), konsole, 
xterm, something else?

- Which shell? E.g. the standard Python interpreter, IDLE, bpython, 
something else?

My guess is that this is not a Python problem, but an issue with your 
console. You should always have your console set to use UTF-8, if 
possible. I expect that your console is set to use a different encoding. 
In that case, see if you can change it to UTF-8. For example, using Gnome 
Terminal on Linux, I can do this:

py> w = u'العربى'
py> print w

and it works fine, but if I change the encoding to WINDOWS-1252 using the 
"Set character encoding" menu command, the terminal will not allow me to 
paste the string into the terminal. 


More information about the Python-list mailing list