473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 10: ordinal not in range(128)

I have no idea what is causing this error, or how to fix it. The full error is:

Traceback (most recent call last):
File "D:\ScriptRuntime\PS\Automation\Handlers\SCMTestTo olResourceToolsBAT.py",
line 60, in Run
PS.Automation.Utility.System.AppendSystemPath(args["PATH"], context)
File "D:\ScriptRuntime\PS\Automation\Utility\System.py" , line 55, in AppendSys
temPath
AppendPathVariable("PATH", appendtext, context)
File "D:\ScriptRuntime\PS\Automation\Utility\System.py" , line 37, in AppendPat
hVariable
if(ap == pp):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 10: ordinal
not in range(128)

The code for the function is:

def AppendPathVariable(variable, appendtext, context):
"""AppendSystemPath(appendtext, context) -> None

Appends a directory string to the system path. The string can be
as single path or multiple paths seperated by a semi-colon."""

if(os.environ.has_key(variable)):
curpath = os.environ[variable]

pathparts = string.split(curpath, ";")
appendparts = string.split(appendtext, ";")

for ap in appendparts:
found = 0

for pp in pathparts:
if(ap == pp):
found = 1

if(found == 0):
pathparts.append(ap)
#end for ap in appendparts

newpath = string.join(pathparts, ";")
os.environ[variable] = newpath
else:
os.environ[variable] = appendtext
Jul 18 '05 #1
4 9329
If you compare a unicode string to a byte string, and the byte-string
has byte values >127, you will get an error like this:
u'a' == '\xc0'

Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: ordinal not in range(128)

There is no sensible way for Python to perform this comparison, because
the byte string '\xc0' could be in any encoding. If the encoding of the
byte string is latin-1, it's LATIN CAPITAL LETTER A WITH GRAVE. If it's
koi8-r encoded, it's CRYILLIC SMALL LETTER YU. Python refuses to guess
in this case.

It doesn't matter whether the unicode string contains any characters
that are non-ASCII characters.

To correct your function, you'll have to know what encoding the byte
string is in, and convert it to unicode using the decode() method,
and compare that result to the unicode string.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFBZdclJd01MZaTXX0RAn3dAJ0SnEr4Rc841EZlZqeDVn Ll5khIvACfcaUz
pym81hgmHf6yv592fGPEw7c=
=HYB+
-----END PGP SIGNATURE-----

Jul 18 '05 #2
It's just a file path. It doesn't *have* any non-ASCII chars in it to
begin with! That's why I don't understand why I'm getting the error.
I didn't get it with Python 2.2, but we just upgraded to
(Active)Python 2.3.
Jul 18 '05 #3

On Fri, Oct 08, 2004 at 12:25:26PM -0700, Robin Siebler wrote:
It's just a file path. It doesn't *have* any non-ASCII chars in it to
begin with!


Well, then, be sure to follow up when you find the real cause, because I
don't know of another reason that isn't along the lines I mentioned.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFBZu25Jd01MZaTXX0RAr4HAJ4p9Isl8/ZGxhZhAWLU39yYszd+WwCfSm4e
A8Lbqnb270taGwlfoE6P3FA=
=kwqz
-----END PGP SIGNATURE-----

Jul 18 '05 #4
[Robin Siebler]
It's just a file path. It doesn't *have* any non-ASCII chars in it to
begin with!
[Jeff Epler]
Well, then, be sure to follow up when you find the real cause, because I
don't know of another reason that isn't along the lines I mentioned.

Robin, your original report disagrees with your belief:
if(ap == pp):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 10: ordinal
not in range(128)


0xa0 is not an ASCII character. We can't tell from the traceback
which of ap and pp is Unicode, and which isn't, but presumably your
knowledge of your app will tell you.

That something is "a file path" doesn't mean anything -- you're
running on Windows, and Windows doesn't restrict paths to containing
ASCII characters.
f = open('\xa0\xa0.txt', 'w')
f.name '\xa0\xa0.txt' f.close()
import os
for fn in os.listdir('.'):

.... if fn.endswith('.txt'):
.... print fn
b.txt
bb.txt
BUILDno.txt
NormalizationTest-3.2.0.txt
readme.txt
áá.txt

The last line may not show up correctly for you, since it contains
non-ASCII characters. When I sent it, it looked like

aa.txt

but with diacritcal marks "on top of" the a's.
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: oziko | last post by:
Hi, I get a piece of code of ogg123.py from the pyogg site, this is the code: ******************************* ogg_file = sys.argv vorbis_file=ogg.vorbis.VorbisFile(ogg_file) comentarios =...
3
by: thomas Armstrong | last post by:
Hi Using Python 2.3.4 + Feedparser 3.3 (a library to parse XML documents) I'm trying to parse a UTF-8 document with special characters like acute-accent vowels: -------- <?xml version="1.0"...
2
by: Francach | last post by:
Hi, I don't know what I'm doing wrong here. I''m using Python 2.4 and py2exe. I get he following error: Traceback (most recent call last): File "notegui.pyc", line 34, in OnClose File...
4
by: Oleg Parashchenko | last post by:
Hello, I'm working on an unicode-aware application. I like to use "print" to debug programs, but in this case it was nightmare. The most popular result of "print" was: UnicodeDecodeError:...
1
by: Eric S. Johansson | last post by:
I'm having a problem (Python 2.4) converting strings with random 8-bit characters into an escape form which is 7-bit clean for storage in a database. Here's an example: body =...
2
by: Gilles Ganault | last post by:
Hello It seems like I have Unicode data in a CSV file but Python is using a different code page, so isn't happy when I'm trying to read and put this data into an SQLite database with APSW: ...
3
by: Gilles Ganault | last post by:
Hello I'm getting this error while downloading and parsing web pages: ===== title = m.group(1) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 48: ordinal not in...
7
by: luca72 | last post by:
hello i have this problem: UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 8: ordinal not in range(128) Generally i solve the problem inserting : # -*- coding:...
0
by: Andreas Bittel | last post by:
Dear Ladies and Sirs, I open a ascii-file with "open", which contains the character: "U+00E7" "ç" "c3 a7". This character is read in a line of the "FileContent"-table. Then I search with "find"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.