473,396 Members | 1,713 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,396 software developers and data experts.

Problems with unicode

I'm trying to write out a XML document using a StringIO class, however
I always run into the following error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position
4: ordinal
not in range(128)

Apparently in the batch that I'm encoding there is one string with
non-ascii characters in it.
Is there any way to just have it encode everything as unicode and not
ascii?
Or should I just strip out non-ascii characters (a last resort which I
do not want to do)
Thanks.
Jul 18 '05 #1
2 1240
In article <a0**************************@posting.google.com >,
ja****@appliedminds.com (James Laamnna) wrote:
Apparently in the batch that I'm encoding there is one string with
non-ascii characters in it. Is there any way to just have it encode
everything as unicode and not ascii?


A better question to ask is this: where did the supposed ASCII data come
from in the first place? If, for instance, it came from a Windows
machine, then there's a chance it's actually ISO-8859-1 encoding, in
which case you can preserve the 0x92 by encoding using that codec,
instead of the 'ascii' one. Similarly, if the original text came from a
Mac, then it's likely in Mac Roman, so if you use the 'mac-roman' codec
you'll be able to preserve the correct character in your resulting
Unicode.

Dave
Jul 18 '05 #2
David Opstad <op****@batnet.com> pisze:
If, for instance, it came from a Windows
machine, then there's a chance it's actually ISO-8859-1 encoding


If it came from Windows, it's actually CP-1252, not Latin-1.

http://www.effbot.org/zone/unicode-gremlins.htm

--
Jarek Zgoda
http://jpa.berlios.de/
Jul 18 '05 #3

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

Similar topics

19
by: Gerson Kurz | last post by:
AAAAAAAARG I hate the way python handles unicode. Here is a nice problem for y'all to enjoy: say you have a variable thats unicode directory = u"c:\temp" Its unicode not because you want it...
14
by: Sebastian Meyer | last post by:
Hi newsgroup, i am trying to replace german special characters in strings like str = re.sub('ö', 'oe', str) When i work with this, i always get the message UniCode Error: ASCII decoding error...
2
by: bobnotbob | last post by:
I have created an application and am trying to call functions from a previously existing dll. I can call some functions fine, but I get a link error an when I try to call any function that takes...
2
by: bobnotbob | last post by:
I have created an application and am trying to call functions from a previously existing dll. I can call some functions fine, but I get a link error an when I try to call any function that takes...
2
by: Michael B. Trausch | last post by:
I am having a slight problem with UTF-8 output with Python. I have the following program: x = 0 while x < 0x4000: print u"This is Unicode code point %d (0x%x): %s" % (x, x, unichr(x)) x +=...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.