简体   繁体   English

使用 python 和 sqlalchemy 连接到 DB2 时出错 - 需要 SQLAlchemy 格式的连接信息

[英]Error connecting to DB2 with python and sqlalchemy - Connection info needed in SQLAlchemy format

I'm trying to connect to an IBM DB2 database using SQLAlchemy connection format but it keeps failing to connect.我正在尝试使用 SQLAlchemy 连接格式连接到 IBM DB2 数据库,但始终无法连接。

I am using these libraries:我正在使用这些库:

!pip install sqlalchemy==1.3.9
!pip install ibm_db_sa
!pip install --force-reinstall ibm_db_sa ibm_db

Loading the connector:加载连接器:

%load_ext sql

My connection string:我的连接字符串:

%sql ibm_db_sa://jqg6xxxx:r9C98t4TY81xxxxx@fbd88901-ebdb-4a4f-a32e-9822b9fb237b.c1ogj3sdxxxxxtu0lqde00.databases.appdomain.cloud:32731/bludb?security=SSL

Error message:错误信息:

Connection info needed in SQLAlchemy format, example:
           postgresql://username:password@hostname/dbname
           or an existing connection: dict_keys([])
'sqlalchemy.cimmutabledict.immutabledict' object does not support item deletion
Connection info needed in SQLAlchemy format, example:
           postgresql://username:password@hostname/dbname
           or an existing connection: dict_keys([])

I am actually using this format but it just won't work.我实际上正在使用这种格式,但它不起作用。

Your connection string seems malformed: instead of ending with /bludb?security=SSL as shown in your question, try instead using the ending below:您的连接字符串似乎格式错误:不要像您的问题中所示那样以/bludb?security=SSL结尾,而是尝试使用以下结尾:

/bludb;security=SSL;

Notice the sem-colon prefix and suffix.注意分号前缀和后缀。

Works for me with SQLAlchemy 1.3.24 and ibm_db 3.1.0 and ibm_db_sa 0.3.7.使用 SQLAlchemy 1.3.24 和 ibm_db 3.1.0 和 ibm_db_sa 0.3.7 为我工作。 Requires that all other parts of the connection string are correct of course.当然,要求连接字符串的所有其他部分都是正确的。

Also: both the prefix ibm_db_sa://.... and db2+ibm_db:// work for me to Db2 on Cloud (lite).另外:前缀ibm_db_sa://....db2+ibm_db://都适用于 Db2 on Cloud (lite)。

The error stated the format is username:password@hostname/dbname .错误指出格式为username:password@hostname/dbname You will see in yours that you added the port number So the the the change will be jqg6xxxx:r9C98t4TY81xxxxx@fbd88901-ebdb-4a4f-a32e-9822b9fb237b.c1ogj3sdxxxxxtu0lqde00.databases.appdomain.cloud/bludb?security=SSL I had the same issue recently and it worked for me.您会在您的端口号中看到您添加了端口号 所以更改将是jqg6xxxx:r9C98t4TY81xxxxx@fbd88901-ebdb-4a4f-a32e-9822b9fb237b.c1ogj3sdxxxxxtu0lqde00.databases.appdomain.cloud/bludb?security=SSL我有同样的问题最近,它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决 SQLAlchemy 连接问题:连接到 IBM Cloud 上托管的 IBM db2 服务器时,“需要 SQLAlchemy 格式的连接信息” - How to fix SQLAlchemy connection problem: 'Connection info needed in SQLAlchemy format' when connecting to IBM db2 server hosted on IBM Cloud 与 IBM Cloud 上的 Db2 的 SQLAlchemy 连接错误 - SQLAlchemy connection error with Db2 on IBM Cloud 如何在 python 中使用 SQLAlchemy 修复与 db2 的连接? - How do I fix connection to db2 using SQLAlchemy in python? 使用 python/SQLAlchemy 连接到 DB2 时出错:不支持“0x0000”参数值“0x0000”。 SQLSTATE=58017 - Error connecting to DB2 with python/SQLAlchemy: “0x0000” Parameter value “0x0000” is not supported. SQLSTATE=58017 sqlalchemy 与 db2 和 kerberos - sqlalchemy with db2 and kerberos Python 使用 sqlalchemy 的 informix DB 的数据库连接 - Python Database connection for informix DB using sqlalchemy 使用 SQLAlchemy 将 dataframe 推送到 db2 数据库时出错 - Error in pushing dataframe to db2 Database using SQLAlchemy 使用SQLAlchemy抛出错误类型08001连接到MSSQL DB - connecting to MSSQL DB using SQLAlchemy throwing error type 08001 Python with sqlalchemy db retrival - Python with sqlalchemy db retrival sqlalchemy 中缺少 zxJDBC 连接器(使用 DB2) - Missing zxJDBC connector in sqlalchemy (With DB2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM