Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > 'ascii' codec can't encode character u'\xf3'

Reply
Thread Tools

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

 
 
oziko
Guest
Posts: n/a
 
      08-16-2004
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(12


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?
 
Reply With Quote
 
 
 
 
Leif K-Brooks
Guest
Posts: n/a
 
      08-16-2004
oziko wrote:
> 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- and encode all strings in that when
they're outputted or set a default encoding.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'ascii' codec can't encode character u'\u2013' thomas Armstrong Python 3 09-30-2005 08:07 PM
MySQL: 'latin-1' codec can't encode character francescomoi@europe.com Python 4 05-13-2005 04:05 PM
Re: 'ascii' codec can't encode character u'\xf3' Martin Slouf Python 6 08-18-2004 06:23 AM
Re: 'ascii' codec can't encode character u'\xf3' oziko Python 2 08-17-2004 04:08 PM
RE: 'ascii' codec can't encode character u'\xf3' Ben Last Python 0 08-17-2004 01:23 PM



Advertisments