'ascii' codec can't encode character u'\xf3'

O

oziko

Hi, I get a piece of code of ogg123.py from the pyogg site, this is the
code:
*******************************
ogg_file = sys.argv[1]

vorbis_file=ogg.vorbis.VorbisFile(ogg_file)
comentarios = vorbis_file.comment()


recognized_comments = ('Artist', 'Album', 'Title', 'Version',
'Organization', 'Genre', 'Description',
'Date', 'Location', 'Copyright', 'Vendor')

comment_dict = {}
for com in recognized_comments:
comment_dict[string.upper(com)] = '%s: %%s' % com

known_keys = comment_dict.keys()

for key, val in comentarios.items():
if key in known_keys:
print comment_dict[key] % val
else:
continue
#print "Unknown comment: %s" % val
****************************

When I run int I get this error:

Album: Trapos
Vendor: Xiph.Org libVorbis I 20020717
Artist: Attaque 77
Traceback (most recent call last):
File "./ogg2sql.py", line 51, in ?
print comment_dict[key] % val
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in
position 15: ordinal not in range(128)


The title of the song has especial carateres Title= Perfección, it is in
espanish. I put at the begining og the scrpit the encodign coment

#!/usr/bin/env python
# -*- coding: UTF8 -*-


As you see the script get the comment og a vorbis file, and all the
comments are in unicode.

So I do not understan why the script uses an ascii codec, Am I not using
Unicode coding?
 
L

Leif K-Brooks

oziko said:
So I do not understan why the script uses an ascii codec, Am I not using
Unicode coding?

The strings use Unicode, but they have to be encoded somehow to be
outputted. The default encoding is ASCII, which doesn't support all of
those fancy Unicode characters. Figure out what encoding your terminal
is expecting (probably utf-8) and encode all strings in that when
they're outputted or set a default encoding.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top