Search code examples
odbcteradatapypi

Python teradata Uda Exec ODBC connection issue


I am using (Anaconda 3) Python 3.6.3 and have installed the Teradata's python module from https://pypi.python.org/pypi/teradata

I've also created a ODBC data source on my system and am able to use it to login successfully (using Teradata SQL Assistant) to a Teradata system (on a different server). Driver version is 13.00.00.09

I've written a small test code which is failing with ODBC connection issue:

 import Teradata

 import pandas as pd

 import sys
 print("attempting TD connection")
 udaExec = teradata.UdaExec(appName="just_td_test",       version="1.0", logConsole=False)
 #
 with udaExec.connect(method="odbc",system="abc", username="aaaaa",password="xxxxx", driver="Teradata") as connect:
     print("connection done. querying now...")
     query = "select top 10 tablename from dbc.tables;"
     df = pd.read_sql(query,connect)
     print(df.head())
 connect.close()    

Error messages:

attempting TD connection
Traceback (most recent call last):
File "td.py", line 16, in <module>
with udaExec.connect(method="odbc",system="abc", username="aaaaa",password="xxxxx", driver="Teradata") as connect:
File "C:\teradata-15.10.0.21.tar\teradata-15.10.0.21\teradata\udaexec.py", line 183, in connect
**args))
File "C:\teradata-15.10.0.21.tar\teradata-15.10.0.21\teradata\tdodbc.py", line 450, in __init__
SQL_NTS, None, 0, None, 0)
OSError: exception: access violation writing 0x0000000000000078
Exception ignored in: <bound method OdbcConnection.__del__ of OdbcConnection(sessionno=0)>
Traceback (most recent call last):
File "C:\teradata-15.10.0.21.tar\teradata-15.10.0.21\teradata\tdodbc.py", line 538, in __del__
self.close()
File "C:\teradata-15.10.0.21.tar\teradata-15.10.0.21\teradata\tdodbc.py", line 513, in close
 connections.remove(self)
 ValueError: list.remove(x): x not in list

Its clear that error is with ODBC connection but the error message is not clear. Teradata ODBC driver version is 13 while pypi provides the Teradata python module of version 15. Is this the reason for the error ?


Solution

  • I am able to solve the issue by (1) Installing ODBC driver v16 and (2) using DSN= instead of system= in the connection string.

    So it appears the reason for my error was the version mismatch of ODBC driver I was using earlier. Hope it helps someone.