Petr Jakeš | 29 Jan 11:06 2012
Picon

troubles with unicode

I am lost,
trying to find solution whole night long.

all attempts to call the set method (see bellow) are finishing:

Page handler: <bound method ProdejniMista.ulozeniProdejnihoMista of <fantomas.controllers.ProdejniMista instance at 0x2ac67a0>> Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/CherryPy-2.3.0-py2.5.egg/cherrypy/_cphttptools.py", line 121, in _run self.main() File "/usr/lib/python2.5/site-packages/CherryPy-2.3.0-py2.5.egg/cherrypy/_cphttptools.py", line 264, in main body = page_handler(*virtual_path, **self.params) File "<string>", line 3, in ulozeniProdejnihoMista File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py", line 360, in expose *args, **kw) File "<string>", line 5, in run_with_transaction File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/database.py", line 359, in so_rwt retval = func(*args, **kw) File "<string>", line 5, in _expose File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py", line 373, in <lambda> mapping, fragment, args, kw))) File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py", line 410, in _execute_func output = errorhandling.try_call(func, *args, **kw) File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/errorhandling.py", line 77, in try_call return func(self, *args, **kw) File "/TG_web/fantomas/controllers.py", line 305, in ulozeniProdejnihoMista prodMisto.set(**slovnikArgumentu) File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/main.py", line 1120, in set self._connection._SO_update(self, args) File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py", line 509, in _SO_update for dbName, value in values]), UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 33: ordinal not in range(128)
I have tried all possible combination to decode/encode the field values and I am really sure all filelds are unicode fields when i am trying call the set method.



automat.set(**slovnikArgumentu)


automat.set(telKontaktniOsoby = slovnikArgumentu[telKontaktniOsoby].encode("utf-8"),
            najemZaRokBezDph = slovnikArgumentu[najemZaRokBezDph].encode("utf-8"),
            kontaktniOsobaPrijmeni = slovnikArgumentu[kontaktniOsobaPrijmeni].encode("utf-8"),
            nazevKontaktMistaPoruchy = slovnikArgumentu[nazevKontaktMistaPoruchy].encode("utf-8"),
            psc = slovnikArgumentu[psc].encode("utf-8"),
            mesto = slovnikArgumentu[mesto].encode("utf-8"),
            adresa2 = slovnikArgumentu[adresa2].encode("utf-8"),
            adresa1 = slovnikArgumentu[adresa1].encode("utf-8"),
            zemDelka = slovnikArgumentu[zemDelka].encode("utf-8"),
            zemSirka = slovnikArgumentu[zemSirka].encode("utf-8"),
            elektrinaZaRokBezDph = slovnikArgumentu[elektrinaZaRokBezDph].encode("utf-8"),
            cisloSignysPartnera = slovnikArgumentu[cisloSignysPartnera].encode("utf-8"),
            pmid = slovnikArgumentu[pmid].encode("utf-8"),
            telReseniPoruchy = slovnikArgumentu[telReseniPoruchy].encode("utf-8"),
            nazevProdejnihoMista = slovnikArgumentu[nazevProdejnihoMista].encode("utf-8"),
            dnuRokOtevreno = slovnikArgumentu[dnuRokOtevreno].encode("utf-8"),
            kontaktniOsobaJmeno = slovnikArgumentu[kontaktniOsobaJmeno].encode("utf-8"))


My Environment:
Ubuntu Hardy Heron 64bit minimal server install

vs2521:/TG_web# yolk -l
Cheetah         - 2.4.4        - active
CherryPy        - 2.3.0        - active
DecoratorTools  - 1.8          - active
Extremes        - 1.1.1        - active
FormEncode      - 1.2.4        - active
Markdown        - 2.1.1        - active
PIL             - 1.1.6        - active
Paste           - 1.7.5.1      - active
PasteDeploy     - 1.5.0        - active
PasteScript     - 1.7.5        - active
PyProtocols     - 1.0a0dev-r2302 - active
Python          - 2.5.2        - active development (/usr/lib/python2.5/lib-dynload)
RuleDispatch    - 0.5a1.dev-r2506 - active
SQLObject       - 0.10.1       - active
TurboCheetah    - 1.0          - active
TurboGears      - 1.0.10       - non-active
TurboGears      - 1.0.8        - active development (/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg)
TurboJson       - 1.1.4        - active
TurboKid        - 1.0.5        - active
configobj       - 4.7.2        - active
egenix-mx-base  - 3.2.2        - active
kid             - 0.9.6        - active
kinterbasdb     - 3.3.0        - active
pip             - 1.0.2        - active
pygooglechart   - 0.3.0        - active
setuptools      - 0.6c11       - non-active
setuptools      - 0.6c12dev-r88846 - active
setuptools      - 0.6c8        - non-active
simplejson      - 2.3.2        - active
wsgiref         - 0.1.2        - active development (/usr/lib/python2.5)
yolk            - 0.4.1        - active

Thanks for your hints

Petr
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 29 Jan 20:29 2012
X-Face

Re: troubles with unicode

Hello!

On Sun, Jan 29, 2012 at 11:06:31AM +0100, Petr Jake?? wrote:
>   File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/main.py",
> line 1120, in set
>     self._connection._SO_update(self, args)
>   File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py",
> line 509, in _SO_update
>     for dbName, value in values]),
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 33: ordinal not in range(128)

   The error means there is at least one 8-bit str mixed with unicode.
If you are sure all values are str instances - what about dbNames?
_SO_update is called from set with dbNames from sqlmeta.columns:

                args = [(self.sqlmeta.columns[name].dbName, value)
                        for name, value in toUpdate.items()]
                self._connection._SO_update(self, args)

   Make sure all dbNames are also str, not unicode.

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
Petr Jakeš | 29 Jan 21:50 2012
Picon

Re: troubles with unicode


  The error means there is at least one 8-bit str mixed with unicode.
If you are sure all values are str instances - what about dbNames?
_SO_update is called from set with dbNames from sqlmeta.columns:

               args = [(self.sqlmeta.columns[name].dbName, value)
                       for name, value in toUpdate.items()]
               self._connection._SO_update(self, args)

  Make sure all dbNames are also str, not unicode.

It looks the type of some fields is changed somewhere during the code execution.
When the set method is called, types of all fields are  OK.
When the SQLObject calls SO_update start, some of the fields and values types are changed (see the printout below).

Any hints?

Petr



 ============= set method start ===============
<type 'str'> telKontaktniOsoby <type 'unicode'> +420721870631
<type 'str'> kontaktniOsobaPrijmeni <type 'unicode'> Kračmar
<type 'str'> nazevKontaktMistaPoruchy <type 'unicode'> Vrátnice
<type 'str'> psc <type 'unicode'> 46117
<type 'str'> mesto <type 'unicode'> Liberec
<type 'str'> geocodeAccuracy <type 'str'> Z
<type 'str'> adresa2 <type 'unicode'>
<type 'str'> adresa1 <type 'unicode'> 17.listopadu 587/4
<type 'str'> zemDelka <type 'unicode'> 15.085940
<type 'str'> zemSirka <type 'unicode'> 50.770829
<type 'str'> elektrinaZaRokBezDph <type 'unicode'> 2052
<type 'str'> kontaktniOsobaJmeno <type 'unicode'> Zdeněk
<type 'str'> cisloSignysPartnera <type 'unicode'> 8
<type 'str'> telReseniPoruchy <type 'unicode'> +420485355214
<type 'str'> nazevProdejnihoMista <type 'unicode'> Kolej LBC B
<type 'str'> dnuRokOtevreno <type 'unicode'> 340
<type 'str'> najemZaRokBezDph <type 'unicode'> 5040

============ _SO_update start =====================
<type 'str'> tel_kontaktni_osoby <type 'str'> +420721870631
<type 'str'> kontaktni_osoba_prijmeni <type 'str'> Kračmar
<type 'unicode'> nazev_kontakt_mista_poruchy <type 'unicode'> Vrátnice
<type 'str'> psc <type 'str'> 46117
<type 'str'> mesto <type 'str'> Liberec
<type 'unicode'> geocode_accuracy <type 'str'> Z
<type 'str'> adresa2 <type 'str'>
<type 'str'> adresa1 <type 'str'> 17.listopadu 587/4
<type 'str'> zem_delka <type 'str'> 15.085940
<type 'str'> zem_sirka <type 'str'> 50.770829
<type 'unicode'> elektrina_za_rok_bez_dph <type 'unicode'> 2052
<type 'str'> kontaktni_osoba_jmeno <type 'str'> Zdeněk
<type 'unicode'> cislo_signys_partnera <type 'unicode'> 8
<type 'str'> tel_reseni_poruchy <type 'str'> +420485355214
<type 'str'> nazev_prodejniho_mista <type 'str'> Kolej LBC B
<type 'unicode'> dnu_rok_otevreno <type 'unicode'> 340
<type 'unicode'> najem_za_rok_bez_dph <type 'unicode'> 5040

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 29 Jan 22:04 2012
X-Face

Re: troubles with unicode

On Sun, Jan 29, 2012 at 09:50:01PM +0100, Petr Jake?? wrote:
>  ============= set method start ===============
> <type 'str'> telKontaktniOsoby <type 'unicode'> +420721870631
> <type 'str'> kontaktniOsobaPrijmeni <type 'unicode'> Kra??mar
> <type 'str'> nazevKontaktMistaPoruchy <type 'unicode'> Vr??tnice
[snip]
> ============ _SO_update start =====================
> <type 'str'> tel_kontaktni_osoby <type 'str'> +420721870631
> <type 'str'> kontaktni_osoba_prijmeni <type 'str'> Kra??mar
> <type 'unicode'> nazev_kontakt_mista_poruchy <type 'unicode'> Vr??tnice
[snip]

   .set() converts fields to backend format using validators attached to
the fields. UnicodeColumns are encoded to strings, but StringColumns are
not, so when you've assigned a unicode object to a StringCol
._SO_update() received that unicode object which is wrong -
._SO_update() has to receive str. Do not assign unicode to StringCol.

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
Petr Jakeš | 29 Jan 22:29 2012
Picon

Re: troubles with unicode


  .set() converts fields to backend format using validators attached to
the fields. UnicodeColumns are encoded to strings, but StringColumns are
not, so when you've assigned a unicode object to a StringCol
._SO_update() received that unicode object which is wrong -
._SO_update() has to receive str. Do not assign unicode to StringCol.


Hmm... I am not getting it.

I am on the Firebird.
The database Default character set = UTF8
ALL text fields in in the table are varchar.
Why the SQLObject things some columns are UnicodeColumns and some columns are StringColumns?

Bingo... it looks like "Mea Culpa":

Because of my laziness I am using fromDatabase = True.
But now, when I have inspected the table definitions, I have found I am (accidentally) mixing two things together in one of the class/tables definition (see the code bellow).
I will investigate this.

Thanks a lot.

Petr

class ProdejniMista(SQLObject):
    class sqlmeta:
        fromDatabase = True # -> nacte vse z databaze bez potreby definice   
#        columnList = True  
    provozovatelMista = ForeignKey('ProvozovatelMista')
    automaty = RelatedJoin('Automaty')
    produkty = RelatedJoin('Produkty')
    nazevProdejnihoMista = UnicodeCol(dbEncoding = "utf-8")
    kontaktniOsobaJmeno = UnicodeCol(dbEncoding = "utf-8")
    kontaktniOsobaPrijmeni = UnicodeCol(dbEncoding = "utf-8")
    mesto = UnicodeCol(dbEncoding = "utf-8")
    adresa1 = UnicodeCol(dbEncoding = "utf-8")
    adresa2 = UnicodeCol(dbEncoding = "utf-8")
    psc = UnicodeCol(dbEncoding = "utf-8")
    zemDelka = UnicodeCol(dbEncoding = "utf-8")
    zemSirka = UnicodeCol(dbEncoding = "utf-8")
    telReseniPoruchy = UnicodeCol(dbEncoding = "utf-8")
    telKontaktniOsoby = UnicodeCol(dbEncoding = "utf-8")
    telKontaktniOsoby = UnicodeCol(dbEncoding = "utf-8")
    automaty = RelatedJoin('Automaty')

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Petr Jakeš | 29 Jan 23:17 2012
Picon

Re: troubles with unicode

I thing I am few steps farther but new problem arised:


  File "/TG_web/fantomas/controllers.py", line 305, in ulozeniProdejnihoMista
    prodMisto.set(**slovnikArgumentu)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/main.py", line 1123, in set
    self._connection._SO_update(self, args)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py", line 512, in _SO_update
    self.query(myQuery)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py", line 683, in query
    return self._dbConnection._query(self._connection, s)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py", line 334, in _query
    self._executeRetry(conn, conn.cursor(), s)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py", line 329, in _executeRetry
    return cursor.execute(query)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in position 101: ordinal not in range(128)


 ============= set method start ===============
<type 'str'> telKontaktniOsoby <type 'unicode'> +420734803579
<type 'str'> kontaktniOsobaPrijmeni <type 'unicode'> Zburník
<type 'str'> nazevKontaktMistaPoruchy <type 'unicode'> recepce
<type 'str'> psc <type 'unicode'> 28835
<type 'str'> mesto <type 'unicode'> Nymburk
<type 'str'> geocodeAccuracy <type 'str'> Z
<type 'str'> adresa2 <type 'unicode'>
<type 'str'> adresa1 <type 'unicode'> Sportovní 1801
<type 'str'> zemDelka <type 'unicode'> 15.058984
<type 'str'> zemSirka <type 'unicode'> 50.178441
<type 'str'> elektrinaZaRokBezDph <type 'unicode'> 2356
<type 'str'> kontaktniOsobaJmeno <type 'unicode'> Tomáš
<type 'str'> cisloSignysPartnera <type 'unicode'> 34
<type 'str'> telReseniPoruchy <type 'unicode'> +420325517801
<type 'str'> nazevProdejnihoMista <type 'unicode'> SC Nymburk
<type 'str'> dnuRokOtevreno <type 'unicode'> 360
<type 'str'> najemZaRokBezDph <type 'unicode'> 10400

============ _SO_update start =====================
<type 'unicode'> tel_kontaktni_osoby <type 'unicode'> +420734803579
<type 'unicode'> kontaktni_osoba_prijmeni <type 'unicode'> Zburník
<type 'unicode'> nazev_kontakt_mista_poruchy <type 'unicode'> recepce
<type 'unicode'> psc <type 'unicode'> 28835
<type 'unicode'> mesto <type 'unicode'> Nymburk
<type 'unicode'> geocode_accuracy <type 'str'> Z
<type 'unicode'> adresa2 <type 'unicode'>
<type 'unicode'> adresa1 <type 'unicode'> Sportovní 1801
<type 'unicode'> zem_delka <type 'unicode'> 15.058984
<type 'unicode'> zem_sirka <type 'unicode'> 50.178441
<type 'unicode'> elektrina_za_rok_bez_dph <type 'unicode'> 2356
<type 'unicode'> kontaktni_osoba_jmeno <type 'unicode'> Tomáš
<type 'unicode'> cislo_signys_partnera <type 'unicode'> 34
<type 'unicode'> tel_reseni_poruchy <type 'unicode'> +420325517801
<type 'unicode'> nazev_prodejniho_mista <type 'unicode'> SC Nymburk
<type 'unicode'> dnu_rok_otevreno <type 'unicode'> 360
<type 'unicode'> najem_za_rok_bez_dph <type 'unicode'> 10400

print myQuery:
UPDATE prodejni_mista SET tel_kontaktni_osoby = ('+420734803579'), kontaktni_osoba_prijmeni = ('Zburník'), nazev_kontakt_mista_poruchy = ('recepce'), psc = ('28835'), mesto = ('Nymburk'), geocode_accuracy = ('Z'), adresa2 = (''), adresa1 = ('Sportovní 1801'), zem_delka = ('15.058984'), zem_sirka = ('50.178441'), elektrina_za_rok_bez_dph = ('2356'), kontaktni_osoba_jmeno = ('Tomáš'), cislo_signys_partnera = ('34'), tel_reseni_poruchy = ('+420325517801'), nazev_prodejniho_mista = ('SC Nymburk'), dnu_rok_otevreno = ('360'), najem_za_rok_bez_dph = ('10400') WHERE id = (19)

print repr(myQuerry)
u"UPDATE prodejni_mista SET tel_kontaktni_osoby = ('+420734803579'), kontaktni_osoba_prijmeni = ('Zburn\xedk'), nazev_kontakt_mista_poruchy = ('recepce'), psc = ('28835'), mesto = ('Nymburk'), geocode_accuracy = ('Z'), adresa2 = (''), adresa1 = ('Sportovn\xed 1801'), zem_delka = ('15.058984'), zem_sirka = ('50.178441'), elektrina_za_rok_bez_dph = ('2356'), kontaktni_osoba_jmeno = ('Tom\xe1\u0161'), cislo_signys_partnera = ('34'), tel_reseni_poruchy = ('+420325517801'), nazev_prodejniho_mista = ('SC Nymburk'), dnu_rok_otevreno = ('360'), najem_za_rok_bez_dph = ('10400') WHERE id = (19)"

Can you send me your suggestions please?

Thanks

Petr

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 29 Jan 23:36 2012
X-Face

Re: troubles with unicode

On Sun, Jan 29, 2012 at 11:17:09PM +0100, Petr Jake?? wrote:
>   File
> "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py",
> line 329, in _executeRetry
>     return cursor.execute(query)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in
> position 101: ordinal not in range(128)

   It seems Firebird DB API driver can't process unicode.

>  ============= set method start ===============
> <type 'str'> telKontaktniOsoby <type 'unicode'> +420734803579
> <type 'str'> kontaktniOsobaPrijmeni <type 'unicode'> Zburn??k
> <type 'str'> nazevKontaktMistaPoruchy <type 'unicode'> recepce
> 
> ============ _SO_update start =====================
> <type 'unicode'> tel_kontaktni_osoby <type 'unicode'> +420734803579
> <type 'unicode'> kontaktni_osoba_prijmeni <type 'unicode'> Zburn??k
> <type 'unicode'> nazev_kontakt_mista_poruchy <type 'unicode'> recepce

   You made all columns StringCol where I've advised you to make them
all UnicodeCol.

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
Petr Jakeš | 30 Jan 01:20 2012
Picon

Re: troubles with unicode


>  ============= set method start ===============
> <type 'str'> telKontaktniOsoby <type 'unicode'> +420734803579
> <type 'str'> kontaktniOsobaPrijmeni <type 'unicode'> Zburn??k
> <type 'str'> nazevKontaktMistaPoruchy <type 'unicode'> recepce
>
> ============ _SO_update start =====================
> <type 'unicode'> tel_kontaktni_osoby <type 'unicode'> +420734803579
> <type 'unicode'> kontaktni_osoba_prijmeni <type 'unicode'> Zburn??k
> <type 'unicode'> nazev_kontakt_mista_poruchy <type 'unicode'> recepce

  You made all columns StringCol where I've advised you to make them
all UnicodeCol.


Hmmm....  I am completely lost :(

I am testing the unicode type and replacing it with the utf-8 encoded string before I am calling the .set() method:

for key, value in argumentsDict.items():
    print type(key), key, type(value), value
    if isinstance(value, unicode):
        argumentsDict[key] = value.encode("utf-8")

It is throwing UnicodeDecodeError anyway.... Grrrr

 ============= set method start ===============
<type 'str'> telKontaktniOsoby value: <type 'str'> value repr: '+420721870631'
<type 'str'> kontaktniOsobaPrijmeni value: <type 'str'> value repr: 'Kra\xc4\x8dmar'
<type 'str'> nazevKontaktMistaPoruchy value: <type 'str'> value repr: 'Vr\xc3\xa1tnice'
<type 'str'> psc value: <type 'str'> value repr: '46117'
<type 'str'> mesto value: <type 'str'> value repr: 'Liberec'
<type 'str'> geocodeAccuracy value: <type 'str'> value repr: 'Z'
<type 'str'> adresa2 value: <type 'str'> value repr: ''
<type 'str'> adresa1 value: <type 'str'> value repr: '17.listopadu 587/12'
<type 'str'> zemDelka value: <type 'str'> value repr: '15.089062'
<type 'str'> zemSirka value: <type 'str'> value repr: '50.770344'
<type 'str'> elektrinaZaRokBezDph value: <type 'str'> value repr: '2052'
<type 'str'> kontaktniOsobaJmeno value: <type 'str'> value repr: 'Zden\xc4\x9bk'
<type 'str'> cisloSignysPartnera value: <type 'str'> value repr: '8'
<type 'str'> telReseniPoruchy value: <type 'str'> value repr: '+420485355217'
<type 'str'> nazevProdejnihoMista value: <type 'str'> value repr: 'Kolej LBC E'
<type 'str'> dnuRokOtevreno value: <type 'str'> value repr: '340'
<type 'str'> najemZaRokBezDph value: <type 'str'> value repr: '6000'
============ _SO_update start =====================
<type 'unicode'> tel_kontaktni_osoby value: <type 'str'> value repr: '+420721870631'
<type 'unicode'> kontaktni_osoba_prijmeni value: <type 'str'> value repr: 'Kra\xc4\x8dmar'
<type 'unicode'> nazev_kontakt_mista_poruchy value: <type 'str'> value repr: 'Vr\xc3\xa1tnice'
<type 'unicode'> psc value: <type 'str'> value repr: '46117'
<type 'unicode'> mesto value: <type 'str'> value repr: 'Liberec'
<type 'unicode'> geocode_accuracy value: <type 'str'> value repr: 'Z'
<type 'unicode'> adresa2 value: <type 'str'> value repr: ''
<type 'unicode'> adresa1 value: <type 'str'> value repr: '17.listopadu 587/12'
<type 'unicode'> zem_delka value: <type 'str'> value repr: '15.089062'
<type 'unicode'> zem_sirka value: <type 'str'> value repr: '50.770344'
<type 'unicode'> elektrina_za_rok_bez_dph value: <type 'str'> value repr: '2052'
<type 'unicode'> kontaktni_osoba_jmeno value: <type 'str'> value repr: 'Zden\xc4\x9bk'
<type 'unicode'> cislo_signys_partnera value: <type 'str'> value repr: '8'
<type 'unicode'> tel_reseni_poruchy value: <type 'str'> value repr: '+420485355217'
<type 'unicode'> nazev_prodejniho_mista value: <type 'str'> value repr: 'Kolej LBC E'
<type 'unicode'> dnu_rok_otevreno value: <type 'str'> value repr: '340'
<type 'unicode'> najem_za_rok_bez_dph value: <type 'str'> value repr: '6000'
2012-01-30 01:13:08,807 cherrypy.msg INFO HTTP: Page handler: <bound method ProdejniMista.ulozeniProdejnihoMista of <fantomas.controllers.ProdejniMista instance at 0x23fd638>>
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/CherryPy-2.3.0-py2.5.egg/cherrypy/_cphttptools.py", line 121, in _run
    self.main()
  File "/usr/lib/python2.5/site-packages/CherryPy-2.3.0-py2.5.egg/cherrypy/_cphttptools.py", line 264, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in ulozeniProdejnihoMista
  File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py", line 360, in expose
    *args, **kw)
  File "<string>", line 5, in run_with_transaction
  File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/database.py", line 359, in so_rwt
    retval = func(*args, **kw)
  File "<string>", line 5, in _expose
  File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py", line 373, in <lambda>
    mapping, fragment, args, kw)))
  File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py", line 410, in _execute_func
    output = errorhandling.try_call(func, *args, **kw)
  File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/errorhandling.py", line 77, in try_call
    return func(self, *args, **kw)
  File "/TG_web/fantomas/controllers.py", line 317, in ulozeniProdejnihoMista
    prodMisto.set(**slovnikArgumentu)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/main.py", line 1123, in set
    self._connection._SO_update(self, args)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py", line 509, in _SO_update
    myQuery = "UPDATE %s SET %s WHERE %s = (%s)" % (so.sqlmeta.table, ", ".join(["%s = (%s)" % (dbName, self.sqlrepr(value)) for dbName, value in values]), so.sqlmeta.idName, self.sqlrepr(so.id))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 4: ordinal not in range(128)

Petr
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Petr Jakeš | 30 Jan 02:23 2012
Picon

Re: troubles with unicode

Finally some small success...

It was necessary to define all the column names and column types  manually in the table Class definition.

Before inserting/updating to the database it is necessary to check, if the inserted value type is the same as declared in the table Class definition (it is not possible to send string in to the integer column for example). Strange.

Is there some way how to check/set/convert column type according to the Class definition?

I know, it is crazy, it is bypassing of the SQLObject functionality.... But I did not find an other solution for the communication with the Firebird database.

Regards

Petr




------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 30 Jan 10:33 2012
X-Face

Re: troubles with unicode

On Mon, Jan 30, 2012 at 02:23:56AM +0100, Petr Jake?? wrote:
> It was necessary to define all the column names and column types  manually
> in the table Class definition.

   That's ok. "fromDatabase" schema guessing in SQLObject is a bit
primitive. It works slightly better for The Big Three (MySQL, Postgres,
SQLite) but still far from ideal.
   You have a chance to improve the machinery for Firebird - it is in
FirebirdConnection class, methods columnsFromSchema and guessClass.

> Before inserting/updating to the database it is necessary to check, if the
> inserted value type is the same as declared in the table Class definition

   That strange - it's the job of validators.

> (it is not possible to send string in to the integer column for example).
> Strange.

   Well, that's that job - IntCol's validator doesn't allow strings but
allows any object that can be coerced to int.

> Is there some way how to check/set/convert column type according to the
> Class definition?

   See the code in .set() that converts input values:

            for name, value in kw.items():
                from_python = getattr(self, '_SO_from_python_%s' % name, None)
                if from_python:
                    dbValue = from_python(value, self._SO_validatorState)
                else:
                    dbValue = value
                to_python = getattr(self, '_SO_to_python_%s' % name, None)
                if to_python:
                    value = to_python(dbValue, self._SO_validatorState)

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2

Gmane