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

Issue in running Python Script in Batch Mode #61

Open sudipto84goswami opened 7 years ago

sudipto84goswami commented 7 years ago

Hi Team,

I am seeing a typical problem in execution on Teradata queries from Python pertaining to ODBC driver. The same script is working fine with root user.

Error Message: with udaExec.connect(method="odbc",system="172.28.130.20", port="1025", username='xxx',password='xxx',database='xxx', autoCommit=False ) as session: File "/app/install/jupyter/anaconda3/lib/python3.5/site-packages/teradata/udaexec.py", line 183, in connect **args)) File "/app/install/jupyter/anaconda3/lib/python3.5/site-packages/teradata/tdodbc.py", line 405, in init connectParams["DRIVER"] = determineDriver(dbType, driver) File "/app/install/jupyter/anaconda3/lib/python3.5/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: ")

The script works pretty fine with root user.

Version: 15.10.0.20 Script is attached for reference. Just re-iterating, this script is working fine with root user. [TDPY.txt](https://github.com/Teradata/PyTd/files/632910/TDPY.txt)

sudipto84goswami commented 7 years ago

It would be really helpful if someone can help me out on this. I am just really clueless on this. The installation is on CentOS Linux release 7.0.1406 (Core)

escheie commented 7 years ago

Are the ODBCINI or ODBCINST environment variables set for your user?

sudipto84goswami commented 7 years ago

Yes. The ODBC variables are itself declared in /etc/profile and also additionally I have set them explicitly before calling the script: as ODBCINI=/opt/teradata/client/15.10/odbc_64/odbc.ini ODBCINSTINI=/opt/teradata/client/15.10/odbc_64/odbcinst.ini export ODBCINI export ODBCINSTINI

sudipto84goswami commented 7 years ago

Dear Gurus,

Desperately waiting for your help to solve this issue.

escheie commented 7 years ago

I suspect there is a bug in /opt/teradata/client/15.10/odbc_64/odbc.ini file installed by the driver.

I believe the InstallDir field should be:

InstallDir=/opt/teradata/client/15.10/odbc_64

instead of

InstallDir=/opt/teradata/client/15.10

Either try editing the InstallDir field in this file or reference the odbc.ini file included in /opt/teradata/client/ODBC_64 instead which has a correct value for InstallDir, e.g.

export ODBCINI=/opt/teradata/client/ODBC_64/odbc.ini

sudipto84goswami commented 7 years ago

I tried the same. But didn't worked. Resulted in same error. What concerns me is that this is running fine with the user ROOT.

Is there any specific location which refers to the ODBC file when switched to a separate user. Pleas

-sh-4.2$ export ODBCINI=/opt/teradata/client/15.10/odbc_64/odbc.ini -sh-4.2$ ./sample_sundar.py Traceback (most recent call last): File "./sample_sundar.py", line 11, in with udaExec.connect(method="odbc",system="XXXX", port="1025", username='XXXX',password='SSSS',database='ZZZZZ', autoCommit=False ) as session: File "/app/install/jupyter/anaconda3/lib/python3.5/site-packages/teradata/udaexec.py", line 183, in connect **args)) File "/app/install/jupyter/anaconda3/lib/python3.5/site-packages/teradata/tdodbc.py", line 405, in init connectParams["DRIVER"] = determineDriver(dbType, driver) File "/app/install/jupyter/anaconda3/lib/python3.5/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: ") -sh-4.2$ ls -lrt /opt/teradata/client/15.10/odbc_64/odbc.ini -rwxrwxrwx 1 root root 2272 Dec 6 20:28 /opt/teradata/client/15.10/odbc_64/odbc.ini

escheie commented 7 years ago

I installed Teradata 15.10 ODBC driver on a new CentOS 7 environment to try to recreate the issue. As long as ODBCINI=/opt/teradata/client/ODBC_64/odbc.ini is set, I don't have any issues creating ODBC connections running as non-root users.

sudipto84goswami commented 7 years ago

The error seems be flagged from tdodbc,py file which seems to work fine with root users. If you can mention what all checks I can do so as to point the user pointing to correct ODBC. The manual export also didn't worked. Is there any mechanism, I can show this to you over screen share to fix this.

escheie commented 7 years ago

Try setting the odbcLibPath parameter to the path of the Driver Manager library installed by the Teradata ODBC Driver. It's possible that when you run as a non-root user the path changes such that the Driver Manager library loaded is not the one provided by Teradata. See issue #43 for more details. I will be traveling the next 7 days and will only have sporadic access so I may be slow to reply if #43 doesn't solve your issue.