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