【发布时间】:2012-10-15 13:16:45
【问题描述】:
我需要使用 SQLAlchemy 创建并连接到数据库 PostgreSQL 9.2。到目前为止,我能够在 UTF-8 中创建完整的数据库,但我无法将非 ASCII 字符放入其中。这就是我连接到数据库的方式:
url = URL(驱动程序名=s'postgresql',用户名='uname',密码='pwd',主机='localhost',端口='5432',数据库='postgres')
self.engine = create_engine(url)
然后我创建新的数据库,切换到它,并开始填充它:一切正常。我明白了:
entercursor.execute(语句,参数)
sqlalchemy.exc.DataError:(DataError)用于编码“UTF8”的无效字节序列:0xec2d43
'插入省份 (codice_regione, codice, tc_provincia_id, nome, sigla) 值 (%(codice_regione)s, %(codice)s, %(tc_provincia_id)s, %(nome)s, %(sigla)s)返回省.id' {'nome': 'Forl\xec-Cesena', 'codice': 40, 'codice_regione': 8, 'tc_provincia_id': 34, 'sigla': 'FC'}
我在 MySQL 5 上为同一个数据库提供了相同的代码,它运行良好。我不知道出了什么问题。我为 unicode 注册了 postgres 的扩展,但这不起作用。我很困惑,我需要更有经验的人的帮助。
【问题讨论】:
标签: python mysql postgresql unicode orm