ASCII encoding error: ordinal not in range(128)

Paul Prescod paulp at ActiveState.com
Tue Mar 20 17:12:00 EST 2001


Jose Isaias Cabrera wrote:
> 
> ...
>
>   File "C:\myprograms\qna0.py", line 1156, in FindIfAttachments
> 
>     name = code.encode()
> 
> UnicodeError: ASCII encoding error: ordinal not in range(128)

I'm going to presume that "code" is a Unicode string. In that case, you
have to say HOW you want it encoded. What do you want to do with the
non-ASCII characters? Probably what you want is:

"abc".encode("Latin-1")

That means that characters between 128 and 255 will be encoded as the
equivalent byte-codes. Characters above 255 will simply not be
representable. I'm presuming that you won't run into any of those...if
you will be, then you need to think about representation some more.

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.activestate.com/pythoncookbook




More information about the Python-list mailing list