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

not able to connect to teradata with python 3.5 #99

Closed vedbeau closed 6 years ago

vedbeau commented 6 years ago

Hi, Please help me to fix this issue

import teradata udaExec = teradata.UdaExec (appName="HelloWorld", version="1.0",logConsole=False) >>> conn = udaExec.connect(method="odbc", DBCName="tdsitcop1.us.dell.com", UID="ravina", PWD="xxx", authentication="LDAP") Traceback (most recent call last): File "", line 1, in File "/opt/datascience/anaconda3/lib/python3.5/site-packages/teradata/udaexec.py", line 183, in connect **args)) File "/opt/datascience/anaconda3/lib/python3.5/site-packages/teradata/tdodbc.py", line 454, in init checkStatus(rc, hDbc=self.hDbc, method="SQLDriverConnectW") File "/opt/datascience/anaconda3/lib/python3.5/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.')

vedbeau commented 6 years ago

Created a file udaexec.ini in /root,but still getting the same problem. Please help /****

ebyhr commented 6 years ago

I can connect to teradata server with Python 3.5. Here is my example. Have you installed Teradata ODBC Driver for Linux?

~/GitHub/tdpy $ pyenv version
3.5.0 (set by /Users/ebyhr/GitHub/tdpy/.python-version)
~/GitHub/tdpy $ 
~/GitHub/tdpy $ cat tdpy.py
import teradata

udaExec = teradata.UdaExec (appName="tdpy", version="1.0",logConsole=False) 
session = udaExec.connect(method="odbc", system="wbtlabserver.teradata.com", username="testuser", password="***");

for row in session.execute("SELECT GetQueryBand()"):
    print(row)

session2 = udaExec.connect("WBT");
for row in session2.execute("SELECT GetQueryBand()"):
    print(row)
~/GitHub/tdpy $ 
~/GitHub/tdpy $ cat udaexec.ini
# Application Configuration
[CONFIG]
appName=TdPy
version=0.1
logConsole=False
dataSourceName=WBT
table=DBC.DBCInfo 

# Default Data Source Configuration
[DEFAULT]
method=odbc
charset=UTF8

# Data Source Definition
[WBT]
system=wbtlabserver.teradata.com
username=testuser
password=***
~/GitHub/tdpy $ 
~/GitHub/tdpy $ python tdpy.py 
Row 1: [=S> ApplicationName=tdpy;Version=1.0;JobID=20180314220449-8;ClientUser=ebyhr;Production=False;udaAppLogFile=/Users/ebyhr/GitHub/tdpy/logs/tdpy.20180314220449-8.log;UtilityName=PyTd;UtilityVersion=15.10.0.21;]
Row 1: [=S> ApplicationName=tdpy;Version=1.0;JobID=20180314220449-8;ClientUser=ebyhr;Production=False;udaAppLogFile=/Users/ebyhr/GitHub/tdpy/logs/tdpy.20180314220449-8.log;UtilityName=PyTd;UtilityVersion=15.10.0.21;]
~/GitHub/tdpy $ 
vedbeau commented 6 years ago

Hi , Thanks for the update Below is the code which i'm using in python.I'm able to connect using BTEQ with LDAP credentials. I'm getting [Teradata][ODBC Teradata Driver][Teradata Database] (210) The UserId, Password or Account is invalid. FailCode = -8017') while executing in python. But i am able to connect through BTEQ

import teradata udaExec = teradata.UdaExec (appName="HelloWorld", version="1.0",logConsole=True) session = udaExec.connect(method="odbc", system="xxxx",username="ravina",password="xxxx");

udaexec.ini file

Application Configuration

[CONFIG] appName=HelloWorld version=0.1 logConsole=True dataSourceName=Teradata ODBC DSN table=DBC.DBCInfo

Default Data Source Configuration

[DEFAULT] method=odbc charset=UTF8

Data Source Definition

[Teradata ODBC DSN] system=hostname username=ravina password=xxxx

Thanks in advance

ebyhr commented 6 years ago

Would you change following 2 lines?

  1. Specify the data source name like this session = udaExec.connect("Teradata ODBC DSN");
  2. Add authentication=LDAP in udaexec.ini

python script

import teradata

udaExec = teradata.UdaExec (appName="HelloWorld", version="1.0",logConsole=True)
session = udaExec.connect("Teradata ODBC DSN");

udaexec.ini

# Application Configuration
[CONFIG]
appName=HelloWorld
version=0.1
logConsole=True
dataSourceName=Teradata ODBC DSN
table=DBC.DBCInfo

# Default Data Source Configuration
[DEFAULT]
method=odbc
charset=UTF8
authentication=LDAP

# Data Source Definition
[Teradata ODBC DSN]
system=hostname
username=ravina
password=xxxx
vedbeau commented 6 years ago

Hi, Now i'm getting the below error after the above changes Check that the ODBC driver is installed and the ODBCINI or ODBCINST environment variables are correctly set.')

echo $ODBCINI /opt/teradata/client/16.20/odbc_64/odbc.ini

odbc.ini [ODBC]

For Data Direct to load its error messages

Data Direct Driver Manager looks for the messages here:

"/opt/teradata/client/16.20/locale/xx_xx/LC_MESSAGES/"

InstallDir=/opt/teradata/client/16.20/odbc_64 Trace=no Pooling=yes

[ODBC Data Sources] Teradata ODBC DSN=Teradata Database ODBC Driver 16.20

[Teradata ODBC DSN]

This key is not necessary and is only to give a description of the data source.

Description=Teradata Database ODBC Driver 16.20

Driver: The location where the ODBC driver is installed to.

Driver=/opt/teradata/client/16.20/odbc_64/lib/tdataodbc_sb64.so

Required: These values can also be specified in the connection string.

DBCName=hostname UID=ravina

vedbeau commented 6 years ago

session = udaExec.connect("Teradata ODBC DSN") 2018-03-15 06:03:19,666 - teradata.udaexec - INFO - Creating connection: {'externalDSN': 'Teradata ODBC DSN', 'username': 'ravina', 'authentication': 'LDAP', 'method': 'odbc', 'system': '10.233.131.80', 'charset': 'UTF8', 'password': 'XXXXXX'} 2018-03-15 06:03:19,667 - teradata.tdodbc - INFO - Loading ODBC Library: libodbc.so 2018-03-15 06:03:19,670 - teradata.tdodbc - INFO - Available drivers: ODBC Drivers, Teradata 2018-03-15 06:03:19,672 - teradata.udaexec - ERROR - Unable to create connection: {'externalDSN': 'Teradata ODBC DSN', 'username': 'ravina', 'authentication': 'LDAP', 'method': 'odbc', 'system': '10.233.131.80', 'charset': 'UTF8', 'password': 'XXXXXX'}

vedbeau commented 6 years ago

Hi , I'm able to connect now. I appreciate your support. Thank you so much