Re: Yet another problem with special characters (Ä, Ö, Ü, etc.)

Dominik Reiter dominik.reiter at epost.de
Thu Oct 10 04:16:34 EDT 2002


Thank you for your answer.
The problem is how my data gets written into the database. Here's a little
code snippet:

## Start Code here

#!/usr/bin/python

import cgi
import ...
import connective  #returns the cursor

form = cgi.FieldStorage()
val = ()
key = ""
for name in form.keys():
    inh = cgi.escape(form[name].value)
    if name == 'enter':
        break
    val = val + (inh,)
    key = key + name + ", "
    dict[name] = inh
key = key[:-2]
cursor = connective.connect()
cursor.execute('INSERT INTO %s (%s) VALUES %s' % (tab, key, val))

## End code here

Everything works ok, but in the form you can enter a city or country --> if
you enter 'Österreich', the value in the corresponding field in the database
now reads '\xd6sterreich'. If I execute a select-statement and print the
results it stays '\xd6sterreich'. This is very annoying, if you know what I
mean ;-)

Do you have any idea how to handle this problem ??

Thanks
Dominik


"Tim Roberts" <timr at probo.com> schrieb im Newsbeitrag
news:356aqukoo5nqrea8v256v97f965q7dbt6a at 4ax.com...
> dominik.reiter at epost.de (Dominik Reiter) wrote:
> >
> >I'm trying to implement a CGI-script, which takes information from a
> >HTML-Form and passes this information into a database. I get the
> >information from the form just fine and the connection to the database
> >also works. But when I do the INSERT-statement and one of the fields
> >contains a German Umlaut (like 'Ö' for example), all I get in the
> >database is \xd6 (for Ö). So if I want to insert 'Österreich' I get
> >'\xd6sterreich'.
>
> Right.  Ö is hex D6 in the Latin-1 encoding.
>
> >If I try this with IDLE or the Shell in PythonWin, it's like this:
> >
> >>>> val = 'Ö'
> >>>> print val
>> >>>> val
> >'\xd6'
>
> Right.  'str' shows the character, 'repr' shows the hex value for
> characters outside 0..127.
>
> >I've implemented the sitecustomize.py and the changing of the default
> >encoding works just fine, but the results to my problem are still the
> >same. I've tried  several different encodings but none worked.
> >
> >Does anybody have an idea as to what I can do to make this work?
>
> It looks to me like it is working perfectly.  Are you getting the wrong
> answer when you actually go to USE this string?
> --
> - Tim Roberts, timr at probo.com
>   Providenza & Boekelheide, Inc.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20021010/ece27916/attachment.html>


More information about the Python-list mailing list