Teradata Python Module

Tools
Tools covers the tools and utilities you use to work with Teradata and its supporting ecosystem. You'll find information on everything from the Teradata Eclipse plug-in to load/extract tools.
Teradata Employee

Re: Teradata Python Module

@rlobera -  Is the "TERADATA" system you are referring to its TDPID or is it an ODBC DSN?   

If its the TDPID,  then make sure TERADATA or TERADATAcop1 is resolveable to an IP address.

If its an ODBC DSN,  then instead of system="TERADATA", try DSN="TERADATA".

Re: Teradata Python Module

Just getting started with Python and Teradata.

I've followed the install process for Teradata Python module. I've installed Python3.5

Here is my code snippet:

import teradata

def main():

# udaExec = teradata.UdaExec (appConfigFile="udaexec.ini")
udaExec = teradata.UdaExec (appName="searchTeradata", version="1.0", logConsole=False)

session = udaExec.connect(method="odbc",system="tdprdcop1",username="uname",password="pass")

print ("hello")
for row in session.execute("SELECT * FROM views.region"):
print(row)

if __name__ == "__main__":
main()

when i put in a valid username/password, i get the following error:

Traceback (most recent call last):

  File "C:\Users\pspann\Documents\AdvancedAnalytics\PythonScripts\searchTeradata.py", line 20, in <module>

    main()

  File "C:\Users\pspann\Documents\AdvancedAnalytics\PythonScripts\searchTeradata.py", line 8, in main

    session = udaExec.connect(method="odbc",system="tdprdcop1",username="validUser",password="validPass")

  File "C:\Users\pspann\AppData\Local\Programs\Python\Python35\Lib\site-packages\teradata-15.10.0.7-py3.5.egg\teradata\udaexec.py", line 137, in connect

  File "C:\Users\pspann\AppData\Local\Programs\Python\Python35\Lib\site-packages\teradata-15.10.0.7-py3.5.egg\teradata\udaexec.py", line 535, in resolveDict

  File "C:\Users\pspann\AppData\Local\Programs\Python\Python35\Lib\site-packages\teradata-15.10.0.7-py3.5.egg\teradata\udaexec.py", line 556, in _resolve

  File "C:\Users\pspann\AppData\Local\Programs\Python\Python35\lib\string.py", line 125, in substitute

    return self.pattern.sub(convert, self.template)

  File "C:\Users\pspann\AppData\Local\Programs\Python\Python35\lib\string.py", line 122, in convert

    self._invalid(mo)

  File "C:\Users\pspann\AppData\Local\Programs\Python\Python35\lib\string.py", line 95, in _invalid

    (lineno, colno))

ValueError: Invalid placeholder in string: line 1, col 8

when i put in an INVALID username/password, i get the following error (as expected):

Traceback (most recent call last):

  File "C:\Users\pspann\Documents\AdvancedAnalytics\PythonScripts\searchTeradata.py", line 16, in <module>

    main()

  File "C:\Users\pspann\Documents\AdvancedAnalytics\PythonScripts\searchTeradata.py", line 8, in main

    session = udaExec.connect(method="odbc",system="tdprdcop1",username="bad",password="bad")

  File "C:\Users\pspann\AppData\Local\Programs\Python\Python35\Lib\site-packages\teradata-15.10.0.7-py3.5.egg\teradata\udaexec.py", line 181, in connect

  File "C:\Users\pspann\AppData\Local\Programs\Python\Python35\Lib\site-packages\teradata-15.10.0.7-py3.5.egg\teradata\udaexec.py", line 169, in connect

  File "C:\Users\pspann\AppData\Local\Programs\Python\Python35\Lib\site-packages\teradata-15.10.0.7-py3.5.egg\teradata\tdodbc.py", line 358, in __init__

  File "C:\Users\pspann\AppData\Local\Programs\Python\Python35\Lib\site-packages\teradata-15.10.0.7-py3.5.egg\teradata\tdodbc.py", line 194, in checkStatus

teradata.api.DatabaseError: (8017, '[28000] [Teradata][ODBC Teradata Driver][Teradata Database] The UserId, Password or Account is invalid. ')

Please advise

Enthusiast

Re: Teradata Python Module

Hi Eric,

The article mentions the option of connecting using the REST API, and the github notes mention:

The unit tests depend on Teradata ODBC being installed and also on access to Teradata REST Services.

I can't find any other references to the REST API, except your Teradata Magazine article.  

Where can I find out more information on the REST API,  is it a product or a download from this site ?

Thanks

Teradata Employee

Re: Teradata Python Module

@yottadata - If you go to the http://www.info.teradata.com web site and search for Teradata REST Services, you will find the Teradata REST Services installation guide which covers how to download, install, and configure the REST API.

Enthusiast

Re: Teradata Python Module

Thank you Eric !

Enthusiast

Re: Teradata Python Module

thank Eric

now is ok

I changed system by DSN

DSN="Teradata"

Teradata Employee

Re: Teradata Python Module

@pwspann - If your username or password includes a "$", you need to escape it using "$$", otherwise the Python module thinks you are referring to an external configuration variable.   I will work on improving the error message.

Teradata Employee

Re: Teradata Python Module

Hi

How would I simulate the following bteq

INSERT INTO .....

.IF ERRORCODE <> 0 THEN .QUIT 1

.IF ACTIVITYCOUNT = 0 THEN .QUIT 1

I know how to catch the error code with the try command but how do I get the activitycount

Teradata Employee

Re: Teradata Python Module

@cw171001 - As per the Python DB API specification, the Cursor object provides a rowcount attribute that should provide the count you're are looking for.  E.g.  

cursor = session.execute("INSERT INTO ....")

print(cursor.rowcount)

Re: Teradata Python Module

thanks Eric,