ValueError: character U+590048 is not in range [U+

2019-08-25 12:30发布

问题:

Could someone help me with the below error while connecting to Teradata from my Python environment.

I'm using ODBC driver method and I've tried all the below existing methods to connect but no luck.

Note: if you are using windows, you can directly use these methods, however the problem comes when you are on MAC OS (not for all though)

USING TERADATA Module and SQL Alchemy.

import teradata
import pyodbc
server='111.00.00.00'
username = 'user'
password = 'pwd'   

udaExec = teradata.UdaExec(appName="test", version="1.0", 
logConsole=True)

ndw_con = udaExec.connect(method = 'odbc',authentication = "LDAP", 
system=server, username=username, password=password)

# SQL ALCHEMY from teradata 
from sqlalchemy import create_engine
user = 'user'
pwd = 'pwd'
host = '1'11.00.00.00'

td_engine = create_engine('teradata://'+user+':'+pwd+'@'+host+':22/' )

result = td_engine.execute('select top 100 * from temp.sampledata')

# USING PYODBC: the below code gave me a new error saying ('01000', " [01000] [unixODBC][Driver Manager]Can't open lib 'Teradata' : file not found (0) (SQLDriverConnect)")

import pyodbc
td_conn = pyodbc.connect('DRIVER= . 
{Teradata};DBCName='+server+';UID='+username+';PWD='+ password, 
 automcommit=True)

cursor = td_conn.cursor()

Regardless, I was unable to made a connection to teradata, could someone let me know what's going on here and how to fix this issue once for all.

Thanks!

回答1:

Found the answer using pyodbc module. Replaced Driver = {Teradata} parameter with full path where the driver is located, check below fpr the full connection string. Please note that this can only be used on MAC OS.

td_conn = pyodbc.connect('DRIVER={/Library/Application Support/teradata/client/16.20/lib/tdataodbc_sbu.dylib};DBCName='+server+';UID='+username+';PWD='+ password, automcommit=True, authentication = "LDAP")