SQLAlchemy Unicode 错误 - 查询 Teradata 数据库 [英] SQLAlchemy Unicode Error - Querying Teradata database

查看:45
本文介绍了SQLAlchemy Unicode 错误 - 查询 Teradata 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Python 的 SQLAlchemy 库来查询 Teradata 数据库.我可以使用以下代码创建引擎.

I'm trying to use Python's SQLAlchemy library to query a Teradata database. I was able to create the engine okay using the following code.

from sqlalchemy import create_engine

td_engine = create_engine('teradata://' + 'usrname' + ':' + 'pswrd' + '@' + 'myOdbcDataSource' + ':22/?charset=UTF8')

但是当我尝试使用引擎时,出现以下错误.

But when I try to use the engine, I get the following error.

ValueError: 字符 U+590048 不在范围 [U+0000;U+10ffff]

ValueError: character U+590048 is not in range [U+0000; U+10ffff]

使用与我尝试过的数据库交互的所有函数都会发生此错误.例如,当我尝试执行以下操作时出现此错误.

This error occurs using all the functions that interact with the database that I tried. For example, I get this error when I try to execute the following.

sqlStr = 'select top 1000 * from myTable;'结果 = td_engine.execute(sqlStr)

再举一个例子,当我尝试执行以下命令时,我遇到了同样的错误.

As another example, I get the same error when I try to execute the following.

td_engine.table_names('mySchema')

错误之前的日志表明正在使用 ODBC 驱动程序连接到数据库,所以我想知道这是否与我配置 ODBC 驱动程序的方式有关.下面是我的 odbc.ini 文件,它位于我的 Mac 上的/Library/ODBC/.

The log right before the error indicates a connection to the database using the ODBC driver is being made so I wonder if this has something to do with the way I configured the ODBC driver. Below is my odbc.ini file located at /Library/ODBC/ on my Mac.

[ODBC Data Sources]
myodbca       = MySQL ODBC 5.3 ANSI Driver
myodbc        = MySQL ODBC 5.3 Unicode Driver
myOdbcDataSource        = Teradata Database ODBC Driver 16.20

[myOdbcDataSource]
Driver                = /Library/Application Support/teradata/client/16.20/lib/tdataodbc_sbu.dylib
DBCName               = myUrl
DefaultDatabase       = myDb
UserName              = usrname
Password              = pswrd
CharacterSet          = UTF8

有人对如何修复此 Unicode 错误并让 SQL Alchemy Teradata 引擎工作有任何想法吗?提前致谢.

Does anyone have any ideas on how to fix this Unicode error and get the SQL Alchemy Teradata engine working? Thank you in advance.

推荐答案

尝试将编码调整为 UTF8:

Try to adjust encoding to UTF8:

from os import environ

environ["NLS_LANG"] = ".AL32UTF8"

这篇关于SQLAlchemy Unicode 错误 - 查询 Teradata 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆