How to connect Python to a DB2 Database with SSL?

2020-04-21 02:00发布

问题:

I have a running DBeaver connection to a DB2 database and now I would like to connect also in Python with the DB2 database securely over SSL. As authenticating I would like to use my windows account instead of giving a PW and UserID, to do so in DBeaver I changed:

javax.net.ssl.keyStoreType = Windows-ROOT
javax.net.ssl.trustStoreType = Windows-MY

Is this also possible with the Python connection? I tried the following to set up the connection:

import ibm_db

connID = ibm_db.connect('DRIVER={IBM DB2 ODBC DRIVER};'
                     'DATABASE=XXXX;'
                     'HOSTNAME=XXXXYYY.net;'  
                     'PORT=9797;'
                     'PROTOCOL=TCPIP;'
                     'SECURITY=ssl;'
                     'SSLSERVERCERTIFICATE=C:/Users/..../cert.cer;'
                     , '', '')
if connID is None:
    print("\nERROR: Unable to connect.")
exit(-1)
print("Connected!")

I get the following error:

 SQLCODE=-30082][CLI Driver] SQL30082N  Security processing failed with reason "17" ("UNSUPPORTED FUNCTION").  SQLSTATE=08001

Some details:

M:\>"C:\Users\.conda\pkgs\ibm_db-3.0.1-py37hfa6e2cd_1\Lib\site-packages\clidriver\bin\db2level.exe"
DB21085I  This instance or install (instance name, where applicable: "*") uses
"64" bits and DB2 code release "SQL11013" with level identifier "0204010F".
Informational tokens are "DB2 v11.1.3031.295", "s1804271300",
"DYN1804271300WIN64", and Fix Pack "3a".
Product is installed at
"C:\Users\.conda\pkgs\ibm_db-3.0.1-py37hfa6e2cd_1\Lib\site-packages\cli
driver" with DB2 Copy Name "IBM Data Server Driver For ODBC and CLI".

I'm using:

  • Python version 2.7.17
  • Ibm_db version 3.0.1