Can't exeute the sample teradatasql python programs

Extensibility
Teradata Employee

Can't exeute the sample teradatasql python programs

Installed the teradatasql library using pip. Using the help session sample program

 

# Copyright 2018 by Teradata Corporation. All rights reserved.
# This sample program demonstrates how to obtain and display session information.

import teradatasql
with teradatasql.connect ('{"host":"slslsl"user":"sjsjsjs","password":"dkdkdkdk"}') as con:
    with con.cursor () as cur:
        cur.execute ('help session')
        row = cur.fetchone ()
        for i in range (0, len (row)):
            print ('{:>40}  {}'.format (cur.description [i][0], row [i]))

 

But get error right away.

 

File "HelpSession.py", line 7, in with teradatasql.connect ('{"host":"slslsl"user":"sjsjsjs","password":"dkdkdkdk"}') as con:

 

AttributeError: module 'teradatasql' has no attribute 'connect'

 

No error on the import though, so library is there.

 

thought?

 

thanks

 

Dave

Tags (2)
4 REPLIES 4
Teradata Employee

Re: Can't exeute the sample teradatasql python programs

@David_Roth Is the sample program working for you now after reinstalling the teradatasql package?

Teradata Employee

Re: Can't exeute the sample teradatasql python programs

Yes it is working now :)

 

A pip list showed that even though the folders and files were there, python did not think they were installed.

 

So, a quick uninstall / install did the trick.

 

thanks

 

Dave

Tags (1)
New Member

Re: Can't exeute the sample teradatasql python programs

Hello,

We are trying to use the same sample program in Cloud Foundry: "cf version 6.32.0+0191c33d9.2017-09-26", we are able to connect but execute is failing.  Our debug statements looks like:

 

Hello World

2019-03-20T14:44:02.051-05:00 [APP/PROC/WEB/0] [OUT] ['FreeTDS']
2019-03-20T14:44:05.198-05:00 [APP/PROC/WEB/0] [OUT] TeradataConnection uConnHandle=1
2019-03-20T14:44:05.198-05:00 [APP/PROC/WEB/0] [OUT] Connection done
2019-03-20T14:44:05.198-05:00 [APP/PROC/WEB/0] [OUT] TeradataCursor uRowsHandle=None
2019-03-20T14:44:05.198-05:00 [APP/PROC/WEB/0] [OUT] cursor done
 
and sample program like this:
 
with teradatasql.connect('{"host":"host1.**bleep**.cc","user":"xxxxxx","password":"xxxxxx"}') as con:
    print(con)
    print("Connection done")
    with con.cursor() as cur:
       print(cur)
       print("cursor done") 
       cur.execute("select count(*) from xxxxxxx")
       print("execute sql")
       row = cur.fetchone ()
       for i in range(0, len(row)):
            print('{:>40}   {}'.format (cur.description [i][0], row[i]))
          
After the cursor is opened, the execute statement is not returning anything.  Any Idea?
 
 
Highlighted
Teradata Employee

Re: Can't exeute the sample teradatasql python programs

Hi @Chase ,

In the future, please create a new forum thread for a new problem. Please don't recycle old forum threads.

 

Regarding your problem, I copied your code snippet into a Python script and specified an actual hostname, username, password, and table name and it worked OK for me.

 

import teradatasql
with teradatasql.connect('{"host":"whomooz","user":"guest","password":"please"}') as con:
    print(con)
    print("Connection done")
    with con.cursor() as cur:
       print(cur)
       print("cursor done") 
       cur.execute("select count(*) from dbc.dbcinfo")
       print("execute sql")
       row = cur.fetchone ()
       for i in range(0, len(row)):
            print('{:>40}   {}'.format (cur.description [i][0], row[i]))

 

Running the script produced the following output:

 

TeradataConnection uConnHandle=1
Connection done
TeradataCursor uRowsHandle=None
cursor done
execute sql
                                Count(*)   3

Please open a customer service incident so that we can assist you further with this problem.

Thanks!