On Nov 29, 2011, at 9:51 PM, Dirk Makowski wrote: > Hello, > > using SQLAlchemy 0.7.3's Inspector, I'm reflecting the columns of a table, > and it fails with this trace: > > File "./main.py", line 106, in <module> > dbmgr.reflect() > File "./main.py", line 32, in reflect > self.fetch_tables(schema='eg') > File "./main.py", line 58, in fetch_tables > cols0 = self.inspector.get_columns(t, schema=schema) > File > "/home/dm/myprojects/Runcible-env/lib/python2.7/site-packages/SQLAlchemy-0.7.3-py2.7-linux-x86_64.egg/sqlalchemy/engine/reflection.py", > line 230, in get_columns > **kw) > File "<string>", line 1, in <lambda> > File > "/home/dm/myprojects/Runcible-env/lib/python2.7/site-packages/SQLAlchemy-0.7.3-py2.7-linux-x86_64.egg/sqlalchemy/engine/reflection.py", > line 46, in cache > ret = fn(self, con, *args, **kw) > File > "/home/dm/myprojects/Runcible-env/lib/python2.7/site-packages/SQLAlchemy-0.7.3-py2.7-linux-x86_64.egg/sqlalchemy/dialects/postgresql/base.py", > line 1191, in get_columns > rows = c.fetchall() > File > "/home/dm/myprojects/Runcible-env/lib/python2.7/site-packages/SQLAlchemy-0.7.3-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py", > line 2985, in fetchall > l = self.process_rows(self._fetchall_impl()) > File > "/home/dm/myprojects/Runcible-env/lib/python2.7/site-packages/SQLAlchemy-0.7.3-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py", > line 2952, in _fetchall_impl > return self.cursor.fetchall() > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: > ordinal not in range(128) > > I have pinned down the cause to be a column's default value which contains a > "ü" character (u umlaut). The query SA emits to get the columns should give > for that column: > attname | format_type | default > | attnotnull | attnum | table_oid > -----------------+-----------------------------+------------------------------------------------+------------+--------+----------- > min_amount_unit | character varying(16) | 'Stück'::character varying > | t | 10 | 43091 > > Running the query from psql prompt, or from a simple script that uses > psycopg2 directly, gives no error. So the problem is SA-related. > (The database's encoding is SQLASCII.)
You'd need to ensure your client charset is utf-8. This would be in your postgresql.conf file. That is also psycopg2 raising the error in the stack trace - the difference is SQLAlchemy uses psycopg2's psycopg2.extensions.UNICODE extension to coerce multibyte characters into Python unicode objects, and if you added this into your psycopg2-only script you'd probably get the same error. Passing use_native_unicode=False to create_engine() would disable the usage of this extension, in which case SQLAlchemy would by default use the utf-8 codec to decode the incoming row. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" 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/sqlalchemy?hl=en.
