467,145 Members | 1,017 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,145 developers. It's quick & easy.

Re: UnicodeDecodeError, 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
>>>E:\Series\Series\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\important\src\airs\gui\AirsFrame.py ", line 575, in

webdispatch.execute(cmd, id, args)

File "D:\backup\important\src\airs\webserver\webdispatc h.py", line
167, in execute

_cmd_dispatcher[cmd](cb, args)

File "D:\backup\important\src\airs\webserver\webdispatc h.py", line
122, in playFile

therep = arg.replace(filemask, thefile)

UnicodeDecodeError: '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**********@verizonwireless.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*********@python.org
Subject: UnicodeDecodeError, 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_PLAYER_ARGS].split():
thefile = args["file"]
filemask = u"%file%"
therep = arg.replace(filemask, thefile) ##### error here
argstr.insert(0, appcfg.options[appcfg.CFG_PLAYER_PATH])

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

cmd.redirect = _getBaseURL("series?cmd_get_series=%i" % args["id"])
cmd.html = ""


It crashes on this:

20:03:49: File
"D:\backup\important\src\airs\webserver\webdispatc h.py", line 117, in
playFile therep = arg.replace(filemask, thefile)

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

20:03:49: Unhandled Error: <type 'exceptions.UnicodeDecodeError'>:
'ascii' codec can't decode byte 0xc2 in position 93: ordinal not in

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

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.
Aug 5 '08 #1
  • viewed: 1443

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ruslan | last post: by
2 posts views Thread by dbri.tcc@gmail.com | last post: by
4 posts views Thread by Robin Haswell | last post: by
7 posts views Thread by kath | last post: by
1 post views Thread by Karl | last post: by
3 posts views Thread by Jorgen Bodde | last post: by
reply views Thread by Edwin.Madari@VerizonWireless.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.