'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.
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.
Solution 1:[1]
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;
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. 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).
Solution 2:[2]
The error stated the format is 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mao |
Solution 2 | pppery |