473,382 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

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?
Jul 18 '05 #1
1 8092
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.
Jul 18 '05 #2

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

Similar topics

12
by: Peter Wilkinson | last post by:
Hello tlistmembers, I am using the encoding function to convert unicode to ascii. At one point this code was working just fine, however, now it has broken. I am reading a text file that has is...
2
by: jau | last post by:
Hi co-listers! I have been off Python for 2 years and now, that i'm used to Eclipse and Java, I decided to start a project with Python to refresh skills this time using Eclipse and TrueStudio....
3
by: thomas Armstrong | last post by:
Hi Using Python 2.3.4 + Feedparser 3.3 (a library to parse XML documents) I'm trying to parse a UTF-8 document with special characters like acute-accent vowels: -------- <?xml version="1.0"...
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
5
by: Mike Currie | last post by:
Can anyone explain why I'm getting an ascii encoding error when I'm trying to write out using a UTF-8 encoder? Thanks Python 2.4.3 (#69, Mar 29 2006, 17:35:34) on win32 Type "help",...
19
by: Thomas W | last post by:
I'm getting really annoyed with python in regards to unicode/ascii-encoding problems. The string below is the encoding of the norwegian word "fødselsdag". I stored the string as "fødselsdag"...
2
by: John Nagle | last post by:
I'm trying to clean up a bad ASCII string, one read from a web page that is supposedly in the ASCII character set but has some characters above 127. And I get this: File...
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:...
7
by: luca72 | last post by:
hello i have this problem: UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 8: ordinal not in range(128) Generally i solve the problem inserting : # -*- coding:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.