Teradata Python Module: fails on first attempt, succeeds on 2nd

Connectivity
teb
N/A

Teradata Python Module: fails on first attempt, succeeds on 2nd

I am new to python, and am finding that my first attempt to connect via ODBC always fails with the error you see below, however the 2nd attempt, immediately afterwards, always succeeds, and does so pretty quickly.  Any thoughts on why this might be?  I would like to test to for a successful connection in a loop, like with a 'try' statement, but not sure how to do that.   All suggestions appreciated.

Here is the test script I'm attempting to run.  ( I just added the queryTimeout to see if it made a difference -- it didn't):

import teradata

udaExec=teradata.UdaExec()

with udaExec.connect("${dataSourceName}") as session:

        for row in session.execute("SELECT max(calendar_dt) from myDB.myTableName", queryTimeout=120):

                print(row)

######### first attempt results###############

bash-3.2$ python testConnection.py

Traceback (most recent call last):

  File "testConnection.py", line 5, in <module>

    with udaExec.connect("${dataSourceName}") as session:

  File "/Applications/anaconda/lib/python3.5/site-packages/teradata/udaexec.py", line 172, in connect

    **args))

  File "/Applications/anaconda/lib/python3.5/site-packages/teradata/tdodbc.py", line 367, in __init__

    checkStatus(rc, hDbc=self.hDbc, method="SQLDriverConnectW")

  File "/Applications/anaconda/lib/python3.5/site-packages/teradata/tdodbc.py", line 199, in checkStatus

    raise DatabaseError(i[2], u"[{}] {}".format(i[0], i[1]), i[0])

teradata.api.DatabaseError: (60, '[HYT00] [Teradata][Unix system error]  60 Socket error - No response received when attempting to connect to the Teradata server')

######## 2nd attempt results ############

bash-3.2$ python testConnection.py

Row 1: [2016-03-25]

2 REPLIES
teb
N/A

Re: Teradata Python Module: fails on first attempt, succeeds on 2nd

I solved this problem with the following.  Not sure if it was the simplest solution, but it worked.

for i in range(3):

        try:

                udaExec1 = teradata.UdaExec (appName="TebTest", version="1.0", logConsole=False)

                session1 = udaExec1.connect(method="odbc", system=mysystem, username="myUserName", password="mypassword");

                df0=pd.read_sql_query("select current_timestamp", session1)

                break

        except:

                print("error connecting session1, will try 3 times, current try is "+str(i))

Re: Teradata Python Module: fails on first attempt, succeeds on 2nd

I am also facing same issue. Any help here?