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

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
name.

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 UnicodeDecodeError *or* just blanks when writing it to
file.
Simplest case:
--------------

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

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 UnicodeDecodeError:

name = "ÅSE"
ref = SOAP_return_value()
fileH = open("/tmp/namelist.txt","a")
fileH.write("name:%s ref:%s \n" % (name,ref))
fileH.close()

This bombs with:

UnicodeEncodeError: '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 1042

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

Similar topics

5
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...
27
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?
3
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...
4
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...
5
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 =...
7
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...
3
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...
4
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:
0
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, ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.