Teradata / PyTd

A Python Module to make it easy to script powerful interactions with Teradata Database in a DevOps friendly way.
MIT License
108 stars 43 forks source link

Unable to connect Teradata using Python 3.6.4 |Anaconda, Inc. #107

Closed vedbeau closed 6 years ago

vedbeau commented 6 years ago

Hi, i'm getting below error while connecting teradata from python. In the below error,i'm getting Available drivers: BLANK I Installed the driver,but its not recognizing.

Please help

session = udaExec.connect("Teradata ODBC DSN"); 2018-05-16 05:24:50,820 - teradata.udaexec - INFO - Creating connection: {'method': 'odbc', 'charset': 'UTF8', 'authentication': 'LDAP', 'system': 'tdsitcop1.us.dell.com', 'username': 'ravina', 'password': 'XXXXXX', 'externalDSN': 'Teradata ODBC DSN'} 2018-05-16 05:24:50,821 - teradata.tdodbc - INFO - Loading ODBC Library: libodbc.so 2018-05-16 05:24:50,822 - teradata.tdodbc - INFO - Available drivers: 2018-05-16 05:24:50,822 - teradata.udaexec - ERROR - Unable to create connection: {'method': 'odbc', 'charset': 'UTF8', 'authentication': 'LDAP', 'system': 'tdsitcop1.us.dell.com', 'username': 'ravina', 'password': 'XXXXXX', 'externalDSN': 'Teradata ODBC DSN'} Traceback (most recent call last):

escheie commented 6 years ago

Are the ODBCINI or ODBCINST environment variables set to tell the libodbc.so Driver Manager where to locate either the odbc.ini or odbcinst.ini files that point to the Teradata ODBC Driver?

vedbeau commented 6 years ago

Thanks For the update. ODBCINI is set

[root@ddlpldst101 ~]# echo $ODBCINI /opt/teradata/client/16.20/odbc_64/odbc.ini [root@ddlpldst101 ~]# snippet from python

session = udaExec.connect("Teradata ODBC DSN") 2018-05-17 01:42:22,429 - teradata.udaexec - INFO - Creating connection: {'method': 'odbc', 'charset': 'UTF8', 'authentication': 'LDAP', 'system': 'tdsitcop1.us.dell.com', 'username': 'ravina', 'password': 'XXXXXX', 'externalDSN': 'Teradata ODBC DSN'} 2018-05-17 01:42:22,429 - teradata.tdodbc - INFO - Loading ODBC Library: libodbc.so 2018-05-17 01:42:22,430 - teradata.tdodbc - INFO - Available drivers: ODBC Drivers, Teradata Database ODBC Driver 16.20 2018-05-17 01:42:22,431 - teradata.udaexec - ERROR - Unable to create connection: {'method': 'odbc', 'charset': 'UTF8', 'authentication': 'LDAP', 'system': 'tdsitcop1.us.dell.com', 'username': 'ravina', 'password': 'XXXXXX', 'externalDSN': 'Teradata ODBC DSN'} Traceback (most recent call last): File "/opt/anaconda3/lib/python3.6/site-packages/teradata/udaexec.py", line 183, in connect **args)) File "/opt/anaconda3/lib/python3.6/site-packages/teradata/tdodbc.py", line 454, in init checkStatus(rc, hDbc=self.hDbc, method="SQLDriverConnectW") File "/opt/anaconda3/lib/python3.6/site-packages/teradata/tdodbc.py", line 231, in checkStatus raise DatabaseError(i[2], u"[{}] {}".format(i[0], msg), i[0]) teradata.api.DatabaseError: (0, '[I] [. Check that the ODBC driver is installed and the ODBCINI or ODBCINST environment variables are correctly set.')

escheie commented 6 years ago

Can you try passing the odbcLibPath="/opt/teradata/client/ODBC_64/libodbc.so" argument to the UdaExec constructor? It looks like it may be trying to use UnixODBC.

udaExec = teradata.UdaExec (appName="HelloWorld", version="1.0", odbcLibPath="/opt/teradata/client/ODBC_64/lib/libodbc.so")

vedbeau commented 6 years ago

That works!!!. Instead of passing the odbclibpath ,how can we overcome or how to set ? Thanks a lot for your support.

escheie commented 6 years ago

You can set it in a /etc/udaexec.ini file so that it becomes the default for all users on the system. E.g.

[CONFIG]
odbcLibPath=/opt/teradata/client/ODBC_64/lib/libodbc.so