[英]Python DB2 SSL connection
I have been running SQL queries (client side) from DB2 databases using ibm_db & ibm_db_dbi with pandas.我一直在使用ibm_db & ibm_db_dbi和 pandas 从DB2数据库运行 SQL 查询(客户端)。 However our company implemented new security standards and I would need a way to secure the connection as well.
然而,我们公司实施了新的安全标准,我也需要一种方法来保护连接。 Running Python3.7 and DB2 10.5
运行Python3.7和DB2 10.5
Below is my current connection string:以下是我当前的连接字符串:
import ibm_db
import ibm_db_dbi
import pandas as pd
dsn_driver = "IBM DB2 ODBC DRIVER"
dsn_database = "EUH0000"
dsn_hostname = "MEUHC.s990.emea.ibm.com"
dsn_port = "0000"
dsn_protocol = "TCPIP"
dsn_uid = "uid"
dsn_pwd = "pwd"
dsn = (
"DRIVER={{IBM DB2 ODBC DRIVER}};"
"DATABASE={0};"
"HOSTNAME={1};"
"PORT={2};"
"PROTOCOL=TCPIP;"
"UID={3};"
"PWD={4};").format(dsn_database, dsn_hostname, dsn_port, dsn_uid, dsn_pwd)
conn = ibm_db.connect(dsn, "", "")
some_query = "SELECT *....." # just an example
pconn = ibm_db_dbi.Connection(conn)
df = pd.read_sql(some_query, pconn)
Is there any way to incorporate SSL for this code?有没有办法为这个代码合并 SSL? Or should I use a different library altogether?
还是我应该完全使用不同的库?
This is, unfortunately, a little complicated, and (hopefully) your DBA can help with some of this.不幸的是,这有点复杂,并且(希望)您的 DBA 可以帮助解决其中的一些问题。
If you're using a Db2 10.5 Fixpack 5 (or newer) client, then you just need to add a couple of parameters in your DSN string:如果您使用的是 Db2 10.5 Fixpack 5(或更新版本)客户端,那么您只需要在 DSN 字符串中添加几个参数:
Security=ssl;
SslServerCertificate=/path/to/file.arm;
Your DBA should be able to provide you with the SslServerCertificate file (or contents).您的 DBA 应该能够为您提供 SslServerCertificate 文件(或内容)。
If you installed a Db2 client separately from the python ibm_db package, then depending on which Db2 client you have installed (ie providing the native libraries for ibm_db
, you might need to install some additional libraries (the IBM GSKit libraries, which provide the SSL functionality for the Db2 client).如果您独立于 python ibm_db 包安装了 Db2 客户端,那么根据您安装的 Db2 客户端(即为
ibm_db
提供本机库),您可能需要安装一些额外的库(IBM GSKit 库,它提供 SSL 功能用于 Db2 客户机)。
With some newer versions of the Db2 driver and to connect to Db2 on Cloud and Db2 Warehouse on Cloud, addint just Security=SSL;
使用一些较新版本的 Db2 驱动程序并连接到 Db2 on Cloud 和 Db2 Warehouse on Cloud,只需添加
Security=SSL;
to the list of parameters works.到参数列表工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.