473,399 Members | 4,192 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,399 software developers and data experts.

Error when trying to write unicode xml to zipfile

I get below error when trying to write unicode xml to a zipfile.

zip.writestr('content.xml', content.toxml())
File "/usr/lib/python2.4/zipfile.py", line 460, in writestr
zinfo.CRC = binascii.crc32(bytes) # CRC-32 checksum
UnicodeEncodeError: 'ascii' codec can't encode character u'\u25cf' in
position 2848: ordinal not in range(128)

Any ideas?

Martin

Jul 9 '07 #1
5 6608
En Mon, 09 Jul 2007 20:11:24 -0300, Martin <ma************@gmail.com>
escribió:
I get below error when trying to write unicode xml to a zipfile.

zip.writestr('content.xml', content.toxml())
File "/usr/lib/python2.4/zipfile.py", line 460, in writestr
zinfo.CRC = binascii.crc32(bytes) # CRC-32 checksum
UnicodeEncodeError: 'ascii' codec can't encode character u'\u25cf' in
position 2848: ordinal not in range(128)

Any ideas?
Encode before writing. Assuming you want to use utf-8:
zip.writestr('content.xml', content.toxml().encode('utf-8'))

In general, when working with unicode, it's best to decode bytes into
unicode as early as possible (when reading input), process only unicode
inside the program, and encode into bytes at the last step (when writing
output).
Some non-unicode-aware libraries may interfere with this flow,
unfortunately.

--
Gabriel Genellina

Jul 10 '07 #2
En Mon, 09 Jul 2007 20:11:24 -0300, Martin <ma************@gmail.com>
escribió:
I get below error when trying to write unicode xml to a zipfile.

zip.writestr('content.xml', content.toxml())
File "/usr/lib/python2.4/zipfile.py", line 460, in writestr
zinfo.CRC = binascii.crc32(bytes) # CRC-32 checksum
UnicodeEncodeError: 'ascii' codec can't encode character u'\u25cf' in
position 2848: ordinal not in range(128)

Any ideas?
Encode before writing. Assuming you want to use utf-8:
zip.writestr('content.xml', content.toxml().encode('utf-8'))

In general, when working with unicode, it's best to decode bytes into
unicode as early as possible (when reading input), process only unicode
inside the program, and encode into bytes at the last step (when writing
output).
Some non-unicode-aware libraries may interfere with this flow,
unfortunately.

--
Gabriel Genellina

Jul 10 '07 #3
Gabriel Genellina wrote:
En Mon, 09 Jul 2007 20:11:24 -0300, Martin <ma************@gmail.com>
escribió:
>I get below error when trying to write unicode xml to a zipfile.

zip.writestr('content.xml', content.toxml())
File "/usr/lib/python2.4/zipfile.py", line 460, in writestr
zinfo.CRC = binascii.crc32(bytes) # CRC-32 checksum
UnicodeEncodeError: 'ascii' codec can't encode character u'\u25cf' in
position 2848: ordinal not in range(128)

Any ideas?

Encode before writing. Assuming you want to use utf-8:
zip.writestr('content.xml', content.toxml().encode('utf-8'))
Unless, obviously, you were serialising to a non-utf8 encoding. But since the
"toxml()" method seems to return unicode here (which sounds surprising), I
expect it a) to provide no XML declaration at all or b) to be broken anyway.

Stefan
Jul 10 '07 #4
Unless, obviously, you were serialising to a non-utf8 encoding. But since the
"toxml()" method seems to return unicode here (which sounds surprising), I
expect it a) to provide no XML declaration at all or b) to be broken anyway.
Or c) the user forgot to specify the encoding= parameter in toxml().

Regards,
Martin
Jul 10 '07 #5
Martin v. Löwis wrote:
>Unless, obviously, you were serialising to a non-utf8 encoding. But since the
"toxml()" method seems to return unicode here (which sounds surprising), I
expect it a) to provide no XML declaration at all or b) to be broken anyway.

Or c) the user forgot to specify the encoding= parameter in toxml().
Then I would expect it a) to serialise to a UTF-8 compatible encoding that
does not require a declaration (which excludes Python unicode) or b) to be
broken. :)

Stefan
Jul 10 '07 #6

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

Similar topics

2
by: Debbie | last post by:
Hi I have developed an application that access an SQL database and installed it on a different machine The installation is successful but when I try to run the application I get the following...
1
by: Jeff Thur | last post by:
I am getting this error when trying to run a stored procedure: Microsoft.VisualBasic.CompilerServices.LateBinding.LateInd exGet(Object o, Object args, String paramnames) +1361...
1
by: Ghanashyam | last post by:
Dotnet Framework 1.1 is installed on my computer running on Windows 2000 Professional.Visual Studio >net 2003 is installed.When I try to create an ASP.NET project I get following error. The web...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
1
by: dipesh | last post by:
I am getting error when trying to Add Web Reference in Visual Studio 2005. "Some of the files required for web references are not installed"
2
by: ticars | last post by:
I'm getting a weird error when trying to access a user control from within a base page during runtime. Here's what I have: I have a master page with a user control on it. I then have a few...
3
by: LRI41 | last post by:
I googled an error message and it came up with two posts on your forum and when I got there it said I needed to register to post my question, I am not sure whether is this the correct place to...
1
by: jonny | last post by:
Went from using Visual Web Develop express to Visual Studio 2005 and getting error when trying to open project. Error message: "One or more projects in the solution could not be loaded for the...
1
by: hbsnam | last post by:
Getting following error when trying to add / submit a listing Warning: in_array() : Wrong datatype for second argument in /home/namibiac/public_html/addlisting.php on line 175 Warning:...
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: 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: 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
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...
0
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,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.