473,326 Members | 2,111 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,326 software developers and data experts.

Ascii codec can't encode

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: ISO-8859-1 -*-
at the top of the file but now he don't work can you help me

thanks

Luca
Oct 30 '08 #1
7 11110
luca72 wrote:
hello i have this problem:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
position 8: ordinal not in range(128)
This is the result of transcoding a Unicode string to ASCII, where the
Unicode string contains a character that is not representable in ASCII.
This happens to me when I try to print such a character because my console
is set to ASCII.
Generally i solve the problem inserting :
# -*- coding: ISO-8859-1 -*-
at the top of the file but now he don't work can you help me
This only tells Python that your sourcecode uses Latin 1 as encoding. It
doesn't affect other files or any input or output streams.

What code exactly triggers the error?

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

Oct 30 '08 #2
Hy the code is this:

Pok\xe9mon

Luca
Oct 30 '08 #3
On 30 Ott, 10:27, luca72 <lucabe...@libero.itwrote:
Hy the code is this:

Pok\xe9mon

Luca
Sorry is the é
Oct 30 '08 #4
Hello Again

the code is this
# -*- coding: ISO-8859-1 -*-
from BeautifulSoup import BeautifulSoup
import urllib
sito = urllib.urlopen('http://text.net/')
esamino = BeautifulSoup(sito)
luca = esamino.findAll('tr', align='center')
lunghezza = len(luca)
messaggio_per_scar = open('me', 'wb')
file_ricerca = open('ri', 'wb')
for dati in range(lunghezza):
gino = luca[dati]
test = gino.findAll(text=True)
print test
valori_a = gino.find("a")["onclick"].split("'")
print valori_a
nome_boot = valori_a[1]
print nome_boot
frase_scar = '/msg '+nome_boot+' xdcc send '+test[0]+'\n\r'
messaggio_per_scar.write(frase_scar)
nome = test[2]
if nome ==' ':
nome = test[4]
frase_ric = nome+' '+test[1]+' '+test[0]+'\n\r'
file_ricerca.write(frase_ric) #here i have the error
messaggio_per_scar.close()
file_ricerca.close()

Regards

Luca
Oct 30 '08 #5
On Thu, 30 Oct 2008 03:01:07 -0700, luca72 wrote:
the code is this
# -*- coding: ISO-8859-1 -*-
from BeautifulSoup import BeautifulSoup import urllib
sito = urllib.urlopen('http://text.net/') esamino = BeautifulSoup(sito)
luca = esamino.findAll('tr', align='center') lunghezza = len(luca)
messaggio_per_scar = open('me', 'wb') file_ricerca = open('ri', 'wb')
for dati in range(lunghezza):
gino = luca[dati]
test = gino.findAll(text=True)
print test
valori_a = gino.find("a")["onclick"].split("'") print valori_a
nome_boot = valori_a[1]
print nome_boot
frase_scar = '/msg '+nome_boot+' xdcc send '+test[0]+'\n\r'
messaggio_per_scar.write(frase_scar)
nome = test[2]
if nome ==' ':
nome = test[4]
frase_ric = nome+' '+test[1]+' '+test[0]+'\n\r'
file_ricerca.write(frase_ric) #here i have the error
messaggio_per_scar.close()
file_ricerca.close()
And which of those line raised the exception? Full traceback please.

I guess it is one of the ``print``\s because `BeatifulSoup` returns
`unicode` objects which may lead to that exception when printed and the
output encoding can not be determined.

Ciao,
Marc 'BlackJack' Rintsch
Oct 30 '08 #6
the arror are:
>>Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 1006, in __unhandled_exception
self.mainThread.user_exception(None, (exctype,excval,exctb), 1)
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugBase.py", line 538, in user_exception
self._dbgClient.eventLoop()
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 921, in eventLoop
self.readReady(self.readstream.fileno())
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
AsyncIO.py", line 67, in readReady
self.handleLine(s)
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 311, in handleLine
self.__dumpVariables(int(frmnr), int(scope), filter)
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 1128, in __dumpVariables
vlist = self.__formatVariablesList(keylist, dict, scope, filter)
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 1594, in __formatVariablesList
valtypestr = unicode(type(value))[1:-1]
TypeError: unbound method __unicode__() must be called with
NavigableString instance as first argument (got nothing instead)

Original exception was:
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClient.py", line 38, in <module>
debugClient.main()
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 1900, in main
self.__interact()
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 897, in __interact
self.eventLoop()
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 921, in eventLoop
self.readReady(self.readstream.fileno())
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
AsyncIO.py", line 67, in readReady
self.handleLine(s)
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 445, in handleLine
execfile(sys.argv[0], self.debugMod.__dict__)
File "/home/luca11/Desktop/prova.py", line 36, in <module>
file_ricerca.write(frase_ric)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
position 8: ordinal not in range(128)

I have solve in this way:

file_ricerca = codecs.open('ri', 'wb', 'ISO-8859-15', 'repalce')

That is not exact what i want because instead of the 'é' i get '?' but
the loop contine.
Thanks

Luca
Oct 30 '08 #7
luca72 wrote:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
position 8: ordinal not in range(128)

I have solve in this way:

file_ricerca = codecs.open('ri', 'wb', 'ISO-8859-15', 'repalce')
That should be 'replace' instead of 'repalce', I assume you just mistyped it
here. In any case, you could use 'UTF-8', which is a good default encoding
and which further allows the full range of Unicode characters.
That is not exact what i want because instead of the 'é' i get '?' but
the loop contine.
Hmmm, weird, I'd say that ISO-8859-15 should support the accented 'é'.
However, this could also be caused by how you look at the file. If the
editor you use to open it uses a different encoding, it will display
garbage.

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

Oct 30 '08 #8

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

Similar topics

1
by: Mark Hahn | last post by:
I'm using the MIMEText module as part of sending email with no problem until I put it through py2exe. Then I get this error: LookupError: unknown encoding: ascii .... on this line ... File...
1
by: oziko | last post by:
Hi, I get a piece of code of ogg123.py from the pyogg site, this is the code: ******************************* ogg_file = sys.argv vorbis_file=ogg.vorbis.VorbisFile(ogg_file) comentarios =...
4
by: francescomoi | last post by:
Hi. I'm trying to store a text within a MySQL field (v 3.23.58) by using MySQLdb (v 1.2.1c3). The text is: "telephone..." (note the last character) And I get this error message:...
3
by: Elmo Mäntynen | last post by:
I want to encode a plaindigest or a hexdigest in base 32. Any hints? Elmo
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"...
2
by: Francach | last post by:
Hi, I don't know what I'm doing wrong here. I''m using Python 2.4 and py2exe. I get he following error: Traceback (most recent call last): File "notegui.pyc", line 34, in OnClose File...
7
by: Steven Reddie | last post by:
My problem starts with wanting " " to actually appear that way in the output rather than an actual encoded 0xA0 byte in the output stream. I thought a way to solve this would be to select...
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:...
1
by: Eric S. Johansson | last post by:
I'm having a problem (Python 2.4) converting strings with random 8-bit characters into an escape form which is 7-bit clean for storage in a database. Here's an example: body =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.