IBM Cloud上Db2的SQLAlchemy连接错误

问题描述 投票:0回答:1

我一直在尝试使用提供的凭证连接到IBM云上托管的IBM DB2服务器。我遵循了说明,但是收到以下错误:

SQLAlchemy格式所需的连接信息,例如:PostgreSQL://用户名:密码@主机名/数据库名或现有连接:dict_keys([])无法加载插件:sqlalchemy.dialects:ibm_db_sa需要的连接信息SQLAlchemy格式,例如:PostgreSQL://用户名:密码@主机名/数据库名或现有连接:dict_keys([])

这是我使用的代码:

# Remember the connection string is of the format:
# %sql ibm_db_sa://my-username:my-password@my-hostname:my-port/my-db-name
# Enter the connection string for your Db2 on Cloud database instance below
# i.e. copy after db2:// from the URI string in Service Credentials of your Db2 instance. Remove             the double quotes at the end.
%sql ibm_db_sa://user:[email protected]:50000/BLUDB

如果您能帮助我解决此错误,我们将不胜感激。

python db2 database-connection ibm-cloud
1个回答
0
投票
if dbInfo['port']==50001: # if we are on the SSL port, add additional parameter for the driver app.config['SQLALCHEMY_DATABASE_URI']=dbInfo['uri']+"Security=SSL;" else: app.config['SQLALCHEMY_DATABASE_URI']=dbInfo['uri']

该代码从Cloud Foundry环境中的凭据变量读取URI。如果端口为50001,则它将使用SSL / TLS来加密连接,并且需要在该URI中添加Security=SSL

© www.soinside.com 2019 - 2024. All rights reserved.