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

Discussion in 'Python' started by oziko, Aug 16, 2004.

  1. oziko

    oziko Guest

    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?
     
    oziko, Aug 16, 2004
    #1
    1. Advertising

  2. 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-8) and encode all strings in that when
    they're outputted or set a default encoding.
     
    Leif K-Brooks, Aug 17, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Slouf
    Replies:
    6
    Views:
    955
    Martin Slouf
    Aug 18, 2004
  2. Ben Last
    Replies:
    0
    Views:
    431
    Ben Last
    Aug 17, 2004
  3. oziko
    Replies:
    2
    Views:
    11,518
    Diez B. Roggisch
    Aug 17, 2004
  4. thomas Armstrong

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

    thomas Armstrong, Sep 30, 2005, in forum: Python
    Replies:
    3
    Views:
    4,516
    John J. Lee
    Sep 30, 2005
  5. Fredrik Lundh
    Replies:
    0
    Views:
    1,815
    Fredrik Lundh
    Sep 30, 2005
Loading...

Share This Page