473,666 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UnicodeDecodeEr ror: '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:\ScriptRunti me\PS\Automatio n\Handlers\SCMT estToolResource ToolsBAT.py",
line 60, in Run
PS.Automation.U tility.System.A ppendSystemPath (args["PATH"], context)
File "D:\ScriptRunti me\PS\Automatio n\Utility\Syste m.py", line 55, in AppendSys
temPath
AppendPathVaria ble("PATH", appendtext, context)
File "D:\ScriptRunti me\PS\Automatio n\Utility\Syste m.py", line 37, in AppendPat
hVariable
if(ap == pp):
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xa0 in position 10: ordinal
not in range(128)

The code for the function is:

def AppendPathVaria ble(variable, appendtext, context):
"""AppendSystem Path(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.h as_key(variable )):
curpath = os.environ[variable]

pathparts = string.split(cu rpath, ";")
appendparts = string.split(ap pendtext, ";")

for ap in appendparts:
found = 0

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

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

newpath = string.join(pat hparts, ";")
os.environ[variable] = newpath
else:
os.environ[variable] = appendtext
Jul 18 '05 #1
4 9369
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 ?
UnicodeDecodeEr ror: '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)

iD8DBQFBZdclJd0 1MZaTXX0RAn3dAJ 0SnEr4Rc841EZlZ qeDVnLl5khIvACf caUz
pym81hgmHf6yv59 2fGPEw7c=
=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)

iD8DBQFBZu25Jd0 1MZaTXX0RAr4HAJ 4p9Isl8/ZGxhZhAWLU39yYs zd+WwCfSm4e
A8Lbqnb270taGwl foE6P3FA=
=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):
UnicodeDecodeEr ror: '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('.t xt'):
.... print fn
b.txt
bb.txt
BUILDno.txt
NormalizationTe st-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
8131
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 = vorbis_file.comment() recognized_comments = ('Artist', 'Album', 'Title', 'Version',
3
20536
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" encoding="UTF-8" standalone="yes"?> .... -------
2
12423
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 "brain.pyc", line 61, in setNote File "points.pyc", line 151, in setNote File "point.pyc", line 100, in writeNote
4
5364
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: 'ascii' codec can't decode byte 0xXX in position 0: ordinal not in range(128) I spent two hours fixing it, and I hope it's done. The solution is one
1
3562
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 = meta.encode('unicode-escape') when given an 8-bit string, (in meta), the code fragment above yields the error below. 'ascii' codec can't decode byte 0xe1 in position 13: ordinal not in range(128)
2
4831
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: ======== sql = "INSERT INTO mytable (col1,col2) VALUES (?,?)" cursor.executemany(sql, records("test.tsv")) """
3
14628
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 range(128) =====
7
11132
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: ISO-8859-1 -*- at the top of the file but now he don't work can you help me thanks Luca
0
1270
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" the string "SearchString" in this line. I receive the following error: "UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 29: ordinal not in range(128)" (FileContent.find(SearchString )<0)
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8783
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.