Python-Jaydebeapi / jpype-使用SSL加密连接到as400 / db2

时间:2020-05-20 08:59:28

标签: python ssl db2 ibm-midrange jaydebeapi

我很努力(几天后)无法通过ssl在as400上连接到我们的db2数据库。 对于使用jaydebeapi进行数据库连接并通过安全连接访问数据库,我需要通过jpype函数将trustStore位置和trustStore密码附加到JVM。 这是我到目前为止所做的一个简短的总结:

import jaydebeapi
import os
import jpype
import pandas as pd
from credentials_getter import get_db2_credentials


class i5Connection:
    def __init__(self, user, password):
        if jpype.isJVMStarted():
            print("already started!")

        filepath_script = os.path.dirname(os.path.abspath(__file__))
        ssl_trust_store_location = filepath_script + "/database/java-certs.jks"

        jar = filepath_script + '/database/jt400.jar'
        jvm_path = jpype.getDefaultJVMPath()
        jpype.startJVM(jvm_path,
                       '-Djava.class.path=%s' % jar,
                       '-Djavax.net.ssl.trustStore=%s' % ssl_trust_store_location +
                       '-Djavax.net.ssl.trustStorePassword=pw')

        connection_string = 'jdbc:as400://172.17.0.1/library'

        print(connection_string)

        self.conn = jaydebeapi.connect('com.ibm.as400.access.AS400JDBCDriver',
                                       connection_string,
                                       {'user': user,
                                        'password': password,
                                        'secure': 'true'},
                                       filepath_script + '/database/jt400.jar')

现在我遇到以下错误消息:

jpype._jexception.java.sql.SQLExceptionPyRaisable: java.sql.SQLException: The application requester cannot establish the connection. (PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target)

如果我从startJVM调用中删除了trustStoreLocation,密码和jaydebeapi调用的安全参数,它将起作用(不加密) 谁能告诉我我做错了什么?我可能还没有找到好的ibm文档?

编辑:Ive找到了一种解决方法:我只是通过密钥工具How do I import an existing Java keystore (.jks) file into a Java installation?将证书手动保存到cacert中。 并不是真正的解决方案,但如果有人也被卡住,希望能有所帮助...

1 个答案:

答案 0 :(得分:0)

这不是 JayDeBeApi 解决方案,但我能够在 Mac 和 Windows 上使用 Python 通过加密连接 using this solution 连接到 HANA。

相关问题