[英]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.