I am new to Python scripting and when I was converting my shell scripts to Python for a Netezza DB call in which a stored procedure is invoked with passed arguments.Everything is working as expected and giving result same as Shell.But in one case if one parameter is null it will read that data from a Netezza table (Varchar field).While I was testing that scenario and try to print the result read from I got a weird error saying " 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)".I tried to convert the value to string but it is not working. Attaching the script for reference. Note:The script may not follow the Python standards.Open to any Suggestions for improving the code
connection
try:
conn_str ="DRIVER={NetezzaSQL};SERVER="+results.host+";PORT=5480;DATABASE="+results.sugarDB+";UID="+results.username+";PWD="+results.password+""
print conn_str
conn_sugar = pyodbc.connect(conn_str,ansi=True)
cur_sugar = conn_sugar.cursor()
if (conn_sugar):
print "Connection successful"
except Exception, e:
print "Error while creating Netezza connection Error:",e
sys.exit(-1)
reading data from Netezza table
try:
checking for null parameter dim list
if str(results.dimList)=="":
print "dimlist is null"
var_query="select LP.DIMENSIONS AS DIMENSIONS from PICASO..LKP_PX_RECOMMEND_METADATA LP where LP.client_id="+results.clientID+""
print var_query
for row in cur_sugar.execute(var_query):
print "line no 62"
print row.DIMENSIONS
conn_sugar.commit();
else:
print "dimlist is not null",results.dimList
v=results.dimList
cur_sugar.execute("{exec SQLTOOLKIT..UDP_PRC_GET_MEDIAPLAN_RECOMMENDATION_3004("+results.clientID+","+results.configID+","+results.jobinstanceID+",'"+results.convBegin+"','"+results.convEnd+"','"+results.jaMeta+"','"+results.sugarDB+"','"+results.dimList+"','"+results.flag+"')}")
conn_sugar.commit();
conn_sugar.close();
except Exception, e:
print "procedure call failed!!! Error :",e
Error coming as
procedure call failed!!! Error : 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
Thanks Anoop R