473,804 Members | 3,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ascii codec can't encode

hello i have this problem:
UnicodeEncodeEr ror: '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 11144
luca72 wrote:
hello i have this problem:
UnicodeEncodeEr ror: '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ühr er: 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...@libe ro.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(s ito)
luca = esamino.findAll ('tr', align='center')
lunghezza = len(luca)
messaggio_per_s car = open('me', 'wb')
file_ricerca = open('ri', 'wb')
for dati in range(lunghezza ):
gino = luca[dati]
test = gino.findAll(te xt=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_s car.write(frase _scar)
nome = test[2]
if nome ==' ':
nome = test[4]
frase_ric = nome+' '+test[1]+' '+test[0]+'\n\r'
file_ricerca.wr ite(frase_ric) #here i have the error
messaggio_per_s car.close()
file_ricerca.cl ose()

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(s ito)
luca = esamino.findAll ('tr', align='center') lunghezza = len(luca)
messaggio_per_s car = open('me', 'wb') file_ricerca = open('ri', 'wb')
for dati in range(lunghezza ):
gino = luca[dati]
test = gino.findAll(te xt=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_s car.write(frase _scar)
nome = test[2]
if nome ==' ':
nome = test[4]
frase_ric = nome+' '+test[1]+' '+test[0]+'\n\r'
file_ricerca.wr ite(frase_ric) #here i have the error
messaggio_per_s car.close()
file_ricerca.cl ose()
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_exc eption
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.__dumpVari ables(int(frmnr ), int(scope), filter)
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase .py", line 1128, in __dumpVariables
vlist = self.__formatVa riablesList(key list, dict, scope, filter)
File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase .py", line 1594, in __formatVariabl esList
valtypestr = unicode(type(va lue))[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.mai n()
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.ar gv[0], self.debugMod._ _dict__)
File "/home/luca11/Desktop/prova.py", line 36, in <module>
file_ricerca.wr ite(frase_ric)
UnicodeEncodeEr ror: '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:
UnicodeEncodeEr ror: '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ühr er: 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
3186
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 "email\Encoders.pyc", line 85, in encode_7or8bit .... which looks like this ...
1
8151
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 = vorbis_file.comment() recognized_comments = ('Artist', 'Album', 'Title', 'Version',
4
12871
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
5988
by: Elmo Mäntynen | last post by:
I want to encode a plaindigest or a hexdigest in base 32. Any hints? Elmo
3
20548
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" encoding="UTF-8" standalone="yes"?> .... -------
2
12436
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 "brain.pyc", line 61, in setNote File "points.pyc", line 151, in setNote File "point.pyc", line 100, in writeNote
7
4536
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 us-ascii or iso-8859-1 as the output encoding, and so used this line in the stylesheet: <xsl:output method="html" encoding="iso-8859-1"/> The XslTransform documentation states something like (I can't locate it now) that the encoding is ignored...
4
5383
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: 'ascii' codec can't decode byte 0xXX in position 0: ordinal not in range(128) I spent two hours fixing it, and I hope it's done. The solution is one
1
3580
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 = meta.encode('unicode-escape') when given an 8-bit string, (in meta), the code fragment above yields the error below. 'ascii' codec can't decode byte 0xe1 in position 13: ordinal not in range(128)
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10076
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.