Hi, I'm facing the current situation and I don't know how to fix it.
What I want to do, of course, is to store unicode data, have unicode data
in the database and retrieve unicode data. But I don't know what I'm
missing.
I defined this simple table in model/__init__.py
language = sa.Table('language', meta.metadata,
sa.Column('id', sa.types.Unicode(length=10),
primary_key=True),
sa.Column('name', sa.types.Unicode(length=255),
nullable=False))
class Language(object):
def __repr__(self):
return "Language<%s, %s>" % (self.id, self.name)
As backend I'm using pgsql 8.3 with a database encoded in UTF-8 and in
my development.ini I have the following line:
sqlalchemy.convert_unicode = true
If I try to store unicode data in the database, when I try to retrieve
it all I get is garbage.
A full example with paster shell (as you can see my database store
garbage too):
In [1]: x = model.Language()
In [2]: x.id = u'es'
In [3]: x.name = u'Español'
In [4]: model.meta.Session.add(x)
In [5]: model.meta.Session.commit()
In [6]: for y in model.meta.Session.query(model.Language).all(): n = y
In [7]: n.id
Out[7]: u'es'
In [8]: n.name
Out[8]: u'Espa\xc3\xb1ol'
In [9]: !psql -d kalendar2
Welcome to psql 8.3.8, the PostgreSQL interactive terminal.
kalendar2=# select * from language;
id | name
----+----------
es | Español
(1 row)
In [10]: n
Out[10]:
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call
last)
...traceback...
/usr/lib/python2.6/pprint.pyc in _safe_repr(object, context, maxlevels,
level)
318 return format % _commajoin(components), readable,
recursive
319
--> 320 rep = repr(object)
321 return rep, (rep and not rep.startswith('<')), False
322
UnicodeEncodeError: 'ascii' codec can't encode characters in position
17-18: ordinal not in range(128)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---