472,358 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
work?
>>>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
_onWebRequest

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.append(therep)
argstr.insert(0, appcfg.options[appcfg.CFG_PLAYER_PATH])

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

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
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 1624

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

Similar topics

1
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
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...
4
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...
7
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...
1
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...
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:...
3
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...
0
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:...
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.