473,597 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error when trying to write unicode xml to zipfile

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

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

Any ideas?

Martin

Jul 9 '07 #1
5 6621
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('c ontent.xml', content.toxml() )
File "/usr/lib/python2.4/zipfile.py", line 460, in writestr
zinfo.CRC = binascii.crc32( bytes) # CRC-32 checksum
UnicodeEncodeEr ror: '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('c ontent.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('c ontent.xml', content.toxml() )
File "/usr/lib/python2.4/zipfile.py", line 460, in writestr
zinfo.CRC = binascii.crc32( bytes) # CRC-32 checksum
UnicodeEncodeEr ror: '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('c ontent.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('c ontent.xml', content.toxml() )
File "/usr/lib/python2.4/zipfile.py", line 460, in writestr
zinfo.CRC = binascii.crc32( bytes) # CRC-32 checksum
UnicodeEncodeE rror: '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('c ontent.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
2207
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 error Application has generated an exception that could not be handled Process id = 0x610 (1552), Thread id=0x1d0(464)
1
1886
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 ASP.Baldwin41_aspx.Button1_Click(Object sender, EventArgs e) +66 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
1
3767
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 server reported the following error when attempting to create or open the web project located at the following 'URL://Localhost/WebApplication1' HTTP 1.1/500 Server error I tried reinstalling the .NET but it did not help me. Any help in this...
5
3620
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 New System.Diagnostics.Process 'p.Start(MDEPDirStr & "macrun.exe", sPPTOut) p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE") 'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
1
2407
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
2213
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 webforms that provide content to the master page. All of these webforms inherit from the same basepage which I created. Within that base page I'm attempting to access the user control. When I try to execute the code, it gives me an error: ...
3
4215
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 post it or not. I did read the FAQ's but did not find them enlightening. The two post that showed up on Google were the same question but with different threads and there was no way to find how if any one has posted a proposed solution, even after I...
1
2501
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 following reason(s): The project file or web has been moved, renamed or is not on your computer.
1
1463
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: in_array() : Wrong datatype for second argument in /home/namibiac/public_html/addlisting.php on line 179 Warning: in_array() : Wrong datatype for second argument in /home/namibiac/public_html/addlisting.php on line 183 Warning: in_array() : Wrong...
0
7971
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
7893
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
8381
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
8040
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
8259
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
6698
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3889
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...

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.