473,699 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unicode & ZSI interaction ??

Dear newsgroup,

I have written a cgi script in Python, and it has worked fine for some
time. Now the installed Python version has been upgraded to 2.4.1 and
I am having problems with non ascii characters.

The core of the problem I have is as follows:

1. The webpage contains a text field where the user enters her/his

2. My cgi script uses the 'cgi' class to extract the name the user
has entered.

3. The cgi script writes the name the user has given to a file.

Now, the webpage in question is in Norway; and many Norwegian names
are not 8bit clean, i.e. they contain characters which can not be
represented with a 7bit ascii encoding. As a consequence I get
*either* a UnicodeDecodeEr ror *or* just blanks when writing it to
Simplest case:

name = "Åse"
fileH = open("/tmp/namelist.txt"," w")
fileH.write(nam e)

In this case the first character in the name variable is not in the
plain 7bit ascii encoding. The code written above runs without errors
or warnings, but the problematic character is simple replaced by a
space in the file '/tmp/namelist.txt'.

More complicated case:
The application uses the SOAP protocol via the ZSI module to
communicate with some other site. The SOAP call returns a variable,
and when this variable is combined with the name variable above I get
the UnicodeDecodeEr ror:

name = "ÅSE"
ref = SOAP_return_val ue()
fileH = open("/tmp/namelist.txt"," a")
fileH.write("na me:%s ref:%s \n" % (name,ref))

This bombs with:

UnicodeEncodeEr ror: 'ascii' codec can't encode character u'\xc5' in
position 45: ordinal not in range(128)

The variable 'ref' returned from the SOAP interaction is (seemingly
....) pure 7bit ascii.

Any suggestions greatly appreciated.

Joakim Hove

Joakim Hove
hove AT ntnu.no /
Tlf: +47 (73 5)9 34 27 / Stabburveien 18
Fax: ............... .. / N-5231 Paradis
http://www.ift.uib.no/~hove/ / 55 91 28 18 / 92 68 57 04
May 13 '06 #1
0 1051

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

Similar topics

by: Edward K. Ream | last post by:
Am I reading pep 277 correctly? On Windows NT/XP, should filenames always be converted to Unicode using the mbcs encoding? For example, myFile = unicode(__file__, "mbcs", "strict") This seems to work, and I'm wondering whether there are any other details to consider. My experiments with Idle for Python 2.2 indicate that os.path.join doesn't work as I expect when one of the args is a Unicode string. Everything
by: EU citizen | last post by:
Do web pages have to be created in unicode in order to use UTF-8 encoding? If so, can anyone name a free application which I can use under Windows 98 to create web pages?
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a DB and display it onscreen. No matter which way I open the file, convert it to Unicode/leave it as is or what ever, I see all single bytes ok, but double bytes become 2 seperate single bytes. Surely there is an easy way to convert these mixed...
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3 script that grabs some web pages from the web, regex parse the data and stores it localy to xml file for further use.. at first i had no problem using python minidom and everything concerning
by: Holger Klawitter | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi there, triggered by the recent questions about sorting, I started digging into my problems with upper('ä')='ä' when using LC_CTYPE and LANG = de_DE.UTF-8. I have checked with Java (toUpperCase()) and C (see attached program, might help others) that my locale is working, but postgres (initdb and postmaster
by: Robert | last post by:
Hello, I'm using Pythonwin and py2.3 (py2.4). I did not come clear with this: I want to use win32-fuctions like win32ui.MessageBox, listctrl.InsertItem ..... to get unicode strings on the screen - best results according to the platform/language settings (mainly XP Home, W2K, ...). Also unicode strings should be displayed as nice as possible at the console with normal print-s to stdout (on varying platforms, different
by: KvS | last post by:
Hi all, I've been reading about unicode in general and using it in Python in particular lately as this turns out to be not so straightforward actually. I wanted to aks two questions: 1) I'm writing a program that interacts with the user through wxPython (unicode build) and stores & retrieves data using PySQLite. As fas as I know now, both packages are capable of handling Python unicode objects (wxPython returns the values of text...
by: Tom Fields | last post by:
Hello! I like to use the XmlTextWriter to write some SVG files. But in some cases, I need the '&' as '&' and not as &amp;. Example: <glyph unicode="&#x4c;"/> Some code-snippet:
by: Vijay | last post by:
Prep Courses for International Certifications, CSTE & CSQA & ISEB & ISTQB &Business Analyst & SOA Certifications in HYDERABAD. After receiving overwhelming response to our last 50+ batches, SPECTRAMIND SOLUTIONS now announces a new batch of Prep Courses for CSQA & CSTE& ISEB & ISTQB & Business Analyst & SOA so as to prepare you thoroughly for the most prestigious certification exams conducted by International organizations. We...
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...
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...
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...
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...
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...
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.