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

I would like to manipulate the external parameters on the fly , instead of passing the external parameter on the command line , in the udaexec.ini file. I can achieve this by using a string Template and safe_substitution.

An example would be -- pseudo python

for row in csr.execute("""SEL * FROM dbc.tablesv WHERE TABLE_KIND=ANY('T','O')"""):

       udaExec.config.section("CONFIG")["DATABASENAME"].setattr(row.databasename)

        udaExec.config.section("CONFIG")["TABLENAME"].setattr(row.tablename)

        session.execute("SHOW TABLE ${DATABASENAME}.${TABLENAME}")

Teradata Employee

Re: Teradata Python Module

Resolved , after looking at teradata module code

csr=session.cursor()

for row in csr.execute("""

    SEL TOP 10 trim(databasename) db,trim(tablename) tbl from dbc.tables WHERE TABLEKIND='T'

"""):

    udaExec.config.sections["CONFIG"]["DATABASENAME"]=row.db

    udaExec.config.sections["CONFIG"]["TABLENAME"]=row.tbl   

    session.execute("SHOW TABLE ${DATABASENAME}.${TABLENAME}")   

Highlighted
Teradata Employee

Re: Teradata Python Module

@cw171001 - Setting external variables programatically is covered in the External Configuration section of the documentation.   There is a simpler way to set these variables, I've updated your example with the preferred syntax:

csr=session.cursor()
for row in csr.execute("""
SEL TOP 10 trim(databasename) db,trim(tablename) tbl from dbc.tables WHERE TABLEKIND='T'
"""):
udaExec.config["DATABASENAME"]=row.db
udaExec.config["TABLENAME"]=row.tbl
session.execute("SHOW TABLE ${DATABASENAME}.${TABLENAME}")
Teradata Employee

Re: Teradata Python Module

Hi,

I am trying to following the code but I am hitting the following error when I run udaExec.connect. Can anyone help me to resolve this?

2015-11-06 08:47:15,725 - teradata.udaexec - INFO - Creating connection: {'username': 'kanda', 'method': 'odbc', 'password': 'XXXXXX', 'system': 'tofvt23'}

2015-11-06 08:47:15,725 - teradata.tdodbc - INFO - Loading ODBC Library: libodbc.so

2015-11-06 08:47:15,728 - teradata.udaexec - ERROR - Unable to create connection: {'username': 'kanda', 'method': 'odbc', 'password': 'XXXXXX', 'system': 'tofvt23'}

Traceback (most recent call last):

  File "/usr/lib/python3.3/site-packages/teradata/udaexec.py", line 169, in connect

    **args))

  File "/usr/lib/python3.3/site-packages/teradata/tdodbc.py", line 358, in __init__

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

  File "/usr/lib/python3.3/site-packages/teradata/tdodbc.py", line 194, in checkStatus

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

teradata.api.DatabaseError: (0, '[632] 523 630')

Thank you!

Teradata Employee

Re: Teradata Python Module

@KandaCan you make sure that ODBCINST or ODBCINI environment variables exist and if not, set them like below assuming you are running on 64-bit Linux?  These environment variables tell the Driver Manager where to find the Teradata ODBC driver.   When I've seen these cryptic error messages before from the driver manager, it was because the environment wasn't setup correctly.  

export ODBCINST=/opt/teradata/client/ODBC_64/odbcinst.ini 

 

or

 

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

Teradata Employee

Re: Teradata Python Module

@ericscheie I did both export and now it works perfectly fine! Thank you!

Not applicable

Re: Teradata Python Module

Hi All,

I just started working on Python. Iam able to connect to Python and extract the data. can any one help me out how to save data to tab delimited file along with column names as headers.

Your help will be greatly appreciated.

Regards,

prabhu

Re: Teradata Python Module

Hi,

I'm pretty new to Teradata and am having some issues with connecting my Python app to Teradata.  I am continually getting "Error 8017" stating that my login or password is incorrect.  It appears I need to specify LDAP as a parameter in the connection string but haven't been able to find any examples on how to do this.  Would anyone have any examples on how to do that?

Thanks!

Teradata Employee

Re: Teradata Python Module

@ejeff1275 - The "Keywords for SQLDriverConnect" section of the Teradata ODBC user guide cover the keywords that can be set via argument or external configuration to the Python module's connect method when using ODBC as the connection method.  Try adding

Authentication=LDAP

to your external Data Source definition, or pass Authentication="LDAP" to the connect method, e.g.

udaExec.connect(..., Authentication="LDAP");

Re: Teradata Python Module

@ericscheie - Thanks for the advice on that!  That worked.  I missed the documentation that contained the available keywords for the connect method.  Appreciate the help!