gpt4 book ai didi

Python 连接到 AWS EC2 中的 Teradata

转载 作者:行者123 更新时间:2023-11-28 21:45:06 29 4
gpt4 key购买 nike

我想从 Teradata 实例中提取数据。客户端代码在 AWS EC2 实例上运行 Python2.7+。

我安装了 unixODBC 驱动程序和 sudo pip install teradata 但我仍然遇到以下异常:

  File "/usr/local/lib/python2.7/site-packages/teradata/tdodbc.py", line 369, in determineDriver
"Available drivers: {}".format(dbType, ",".join(drivers)))
teradata.api.InterfaceError: ('DRIVER_NOT_FOUND', "No driver found for 'Teradata'. Available drivers: PostgreSQL,MySQL")

代码如下:

import sys
import teradata
# my own imports
td = TeradataClient(DEFAULT_HOSTNAME, DEFAULT_USERNAME, DEFAULT_PASSWORD)
td.select(query, outfile)

我创建的调用Teradata的TeradataClient类如下:

class TeradataClient:
def __init__(self, hostname, username, password):
self._hostname = hostname
self._username = username
self._password = password
self._udaExec = teradata.UdaExec(appName="MyApp", version="1.0", logConsole=False)


def select(self, query, outfile, sep=DEFAULT_SEPARATOR, nullstr=DEFAULT_NULL_STR):
with self._udaExec.connect(method="odbc", system=self._hostname, username=self._username,
password=self._password) as session:
print 'Connection to Teradata established'
with open(outfile,'w') as fp:
with session.cursor() as cursor:
for row in cursor.execute(query):
lineparts = [str(x if x!=None else nullstr) for x in row]
fp.write('%s\n' %sep.join(lineparts))

我该如何解决这个问题?是否需要安装其他 ODBC 驱动程序?

最佳答案

这解决了我的问题:

export ODBC_VERSION=14.10
export ODBCINI=/opt/teradata/client/$ODBC_VERSION/odbc_64/odbc.ini
export ODBCINSTINI=/opt/teradata/client/$ODBC_VERSION/odbc_64/odbcinst.ini
export LD_LIBRARY_PATH=/opt/teradata/client/$ODBC_VERSION/odbc_64/lib:/opt/teradata/client/$ODBC_VERSION/tdicu/lib64:$LD_LIBRARY_PATH
export NLSPATH=/opt/teradata/client/$ODBC_VERSION/odbc_64/msg/tdodbc.cat

注意:

  • 根据需要更改 $ODBC_VERSION
  • udaExec.connect中的system kwarg更新/etc/resolv.conf

关于Python 连接到 AWS EC2 中的 Teradata,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39882352/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com