473,785 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: UnicodeDecodeEr ror, how to elegantly deal with this?

Hi Edwin,

Filemask is obvious as it is assigned in the python code itself. It is
"%file%". The idea is that the file clicked is substituted for the
"%file%" by the replace action. The file that needs to be substituted
is a simple file on disk.

Here is a dump of the file and it's characters. I do understand that
it is not in the range of ASCII but how can I make it so that it will
work?
>>>E:\Series\Se ries\American Dad\American Dad - S03E15 - Stanny Slickers II, The Legend of OllieÂŽs Gold.avi
E (69): (58)\ (92)S (83)e (101)r (114)i (105)e (101)s (115)\ (92)S
(83)e (101)r (114)i (105)e (101)s (115)\ (92)A (65)m (109)e (101)r
(114)i (105)c (99)a (97)n (110) (32)D (68)a (97)d (100)\ (92)A (65)m
(109)e (101)r (114)i (105)c (99)a (97)n (110) (32)D (68)a (97)d (100)
(32)- (45) (32)S (83)0 (48)3 (51)E (69)1 (49)5 (53) (32)- (45)
(32)S (83)t (116)a (97)n (110)n (110)y (121) (32)S (83)l (108)i
(105)c (99)k (107)e (101)r (114)s (115) (32)I (73)I (73), (44) (32)T
(84)h (104)e (101) (32)L (76)e (101)g (103)e (101)n (110)d (100)
(32)o (111)f (102) (32)O (79)l (108)l (108)i (105)e (101)Â (194)Ž
(180)s (115) (32)G (71)o (111)l (108)d (100). (46)a (97)v (118)i
(105)Traceback (most recent call last):

File "D:\backup\impo rtant\src\airs\ gui\AirsFrame.p y", line 575, in
_onWebRequest

webdispatch.exe cute(cmd, id, args)

File "D:\backup\impo rtant\src\airs\ webserver\webdi spatch.py", line
167, in execute

_cmd_dispatcher[cmd](cb, args)

File "D:\backup\impo rtant\src\airs\ webserver\webdi spatch.py", line
122, in playFile

therep = arg.replace(fil emask, thefile)

UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xc2 in position
93: ordinal not in range(128)

----

I assume it is about this part:

OllieÂŽs Gold.avi

But what can I do to decode that properly?

With regards,
- Jorgen


On Mon, Aug 4, 2008 at 8:46 PM, <Ed**********@v erizonwireless. comwrote:
if you can print out values of 'filemask', and 'thefile' variables, whenit crashes, I can help.

thx. Edwin

-----Original Message-----
From: py************* *************** *************** *******@python. org
[mailto:py****** *************** *************** **************@ python.org]
On Behalf Of Jorgen Bodde
Sent: Monday, August 04, 2008 2:24 PM
To: py*********@pyt hon.org
Subject: UnicodeDecodeEr ror, how to elegantly deal with this?
Hi All,

I am relatively new to python unicode pains and I would like to have
some advice. I have this snippet of code:

def playFile(cmd, args):
argstr = list()
for arg in appcfg.options[appcfg.CFG_PLAY ER_ARGS].split():
thefile = args["file"]
filemask = u"%file%"
therep = arg.replace(fil emask, thefile) ##### error here
argstr.append(t herep)
argstr.insert(0 , appcfg.options[appcfg.CFG_PLAY ER_PATH])

try:
subprocess.Pope n( argstr )
except OSError:
cmd.html = "<h1>Can't play file</h1></br>" + args["file"]
return

cmd.redirect = _getBaseURL("se ries?cmd_get_se ries=%i" % args["id"])
cmd.html = ""

-------------------

It crashes on this:

20:03:49: File
"D:\backup\impo rtant\src\airs\ webserver\webdi spatch.py", line 117, in
playFile therep = arg.replace(fil emask, thefile)

20:03:49: UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xc2 in
position 93: ordinal not in range(128)

20:03:49: Unhandled Error: <type 'exceptions.Uni codeDecodeError '>:
'ascii' codec can't decode byte 0xc2 in position 93: ordinal not in
range(128)

It chokes on a ` character in a file name. I read this file from disk,
and I would like to play it. However in the replace action it cannot
translate this character. How can I transparently deal with this issue
because in my eyes it is simply replacing a string with a string, and
I do not want to be bothered with unicode problems. I am not sure in
which encoding it is in, but I am not experienced enough to see how I
can solve this

Can anybody guide me to an elegant solution?

Thanks in advance!
- Jorgen
--
http://mail.python.org/mailman/listinfo/python-list

The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list
Aug 5 '08 #1
0 1732

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

Similar topics

1
4912
by: Ruslan | last post by:
Hi, everybody. In this excerpt of code enc = 'some_type_of_encoding' def _encode(v): if isinstance(v, UnicodeType): v = v.encode(v) return v
2
1582
by: dbri.tcc | last post by:
Hello I am getting somewhat random UnicodeDecodeError messages in my program. It is random in that I will be going through a pysqlite database of records, manipulate the results, and it will throw UnicodeDecodeError apparently without regard as to what data is being used.
4
3514
by: Robin Haswell | last post by:
Okay I'm getting really frustrated with Python's Unicode handling, I'm trying everything I can think of an I can't escape Unicode(En|De)codeError no matter what I try. Could someone explain to me what I'm doing wrong here, so I can hope to throw light on the myriad of similar problems I'm having? Thanks :-) Python 2.4.1 (#2, May 6 2005, 11:22:24) on linux2 Type "help", "copyright", "credits" or "license" for more information.
7
3027
by: kath | last post by:
I have a number of excel files. In each file DATE is represented by different name. I want to read the date from those different file. Also the date is in different column in different file. To identify the date field in different files I have created a file called _globals where I keep all aliases for DATE in a array called 'alias_DATE'. Array alias_DATE looks like,
1
2390
by: Karl | last post by:
error msg: Mod_python error: "PythonHandler mod_python.publisher" Traceback (most recent call last): File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch result = object(req) File "/usr/lib/python2.3/site-packages/mod_python/publisher.py",
4
5379
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
3
6640
by: Jorgen Bodde | last post by:
Hi All, I am relatively new to python unicode pains and I would like to have some advice. I have this snippet of code: def playFile(cmd, args): argstr = list() for arg in appcfg.options.split(): thefile = args filemask = u"%file%"
0
263
by: Edwin.Madari | last post by:
if you can print out values of 'filemask', and 'thefile' variables, when it crashes, I can help. thx. Edwin -----Original Message----- From: python-list-bounces+edwin.madari=verizonwireless.com@python.org On Behalf Of Jorgen Bodde Sent: Monday, August 04, 2008 2:24 PM To: python-list@python.org
3
14641
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) =====
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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
10152
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...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
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
4053
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
3
2880
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.