Author Topic: accessing ibm i database from Python  (Read 819 times)

joelj

  • Newbie
  • *
  • Posts: 2
    • View Profile
accessing ibm i database from Python
« on: November 28, 2018, 06:15:53 pm »
Good morning.

I have Python 3.7.1 installed on my windows 10 PC. I ma using Idle as editor. I am trying to do basic connection to an IBM i server.

import ibm_db
import ibm_db_dbi

database = "IBMINAME"
user = "JOEL"
password = "PASSWORD"

#ibm_db_conn = ibm_db.connect(database,user,password)
print("AA")

#ibm_db_conn = ibm_db.connect("DATABASE=IBMINAME;HOSTNAME=IBMINAME;PORT=8471;PROTOCOL=TCPIP;UID=JOEL;PWD=PASSWORD;", "", "")
#conn = ibm_db_dbi.Connection(ibm_db_conn)

conn = ibm_db_dbi.connect("DATABASE=IBMINAME;HOSTNAME=IBMINAME;PORT=8471;PROTOCOL=TCPIP;UID=JOEL;PWD=PASSWORD;", "", "")

print("BB")
sql = "select GFCUS from KFILFBI.GFPF"
cursor = conn.cursor()
cursor.execute(sql)
for row in cursor.fetchall():
    print(row)
    print("CC")
cursor.close()
conn.close()


I only get a printout of AA on my idle console. Any ideas why? There are no errors on the Idle console. When i use port 50000 or 60000, i get :

Exception: [IBM][CLI Driver] SQL30081N  A communication error has been detected. Communication protocol being used: "TCP/IP".  Communication API being used: "SOCKETS".  Location where the error was detected: "xx.xxx.xxx.xxx".  Communication function detecting the error: "connect".  Protocol specific error code(s): "10061", "*", "*".  SQLSTATE=08001
 SQLCODE=-30081

Another thing, when i use port 8471, I do not get the SQL30081N  error above. 8471 is the port used by ibm database server jobs. But still, i only get AA, it looks like the code get stuck on the connection part, it doesnt get to the line where BB is supposed to be printed.

I tried adding firewall exceptions for port 8471 and 50000 60000, still same problem.

Do you have any ideas i can work on?

thanks,
Joel
« Last Edit: November 28, 2018, 06:18:27 pm by joelj »

Share on Facebook Share on Twitter

Like Like x 1 View List

joelj

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: accessing ibm i database from Python
« Reply #1 on: November 29, 2018, 05:40:12 am »
was able to make it work using pyodbc. very useful reference here:
https://ochiba77.blogspot.com/2011/09/how-to-connect-db2-with-python-pyodbc.html?showComment=1543491397417#c3112663716830198386

Many thanks to the Omi Chiba.