简体   繁体   中英

How do I fix connection to db2 using SQLAlchemy in python?

I'm having trouble connecting to my database BLUDB in IBM Db2 on Cloud using SQLAlchemy. Here is the code I've always used and it's always worked fine:

%sql ibm_db_sa://user:pswd@some-host.services.dal.bluemix.net:50000/BLUDB

But now I get this error:

(ibm_db_dbi.ProgrammingError) ibm_db_dbi::ProgrammingError: Exception('[IBM][CLI Driver] SQL1042C An unexpected system error occurred. SQLSTATE=58004\\r SQLCODE=-1042') (Background on this error at: http://sqlalche.me/e/13/f405) Connection info needed in SQLAlchemy format, example: postgresql://username:password@hostname/dbname or an existing connection: dict_keys([])

These packages are loaded as always:

import ibm_db
import ibm_db_sa
import sqlalchemy
from sqlalchemy.engine import create_engine

I looked at the python db2 documentation on ibm and the sqlalchemy error message but couldn't get anywhere.

I am working in Jupyterlab locally. I've recently reinstalled Python and Jupyterlab. That's the only thing locally that's changed.

I am able to successfully run the notebooks in the cloud at kaggle and cognitive class. I am also able to connect and query sqlite3 via python without an issue using my local notebook.

All the ibm modules and version numbers are the same before and after installation. I used requirements.txt for reinstallation.

In db2diag.log here are the last two entries:

2020-11-05-14.06.47.081000-300 I13371F372 LEVEL: Warning PID : 17500 TID : 7808 PROC : python.exe INSTANCE: NODE : 000 HOSTNAME: DESKTOP-6FFFO2E EDUID : 7808 FUNCTION: DB2 UDB, bsu security, sqlexLogPluginMessage, probe:20 DATA #1 : String with size, 43 bytes loadAuthidMapper: GetModuleHandle rc = 126

2020-11-05-14.13.49.282000-300 I13745F373 LEVEL: Warning PID : 3060 TID : 12756 PROC : python.exe INSTANCE: NODE : 000 HOSTNAME: DESKTOP-6FFFO2E EDUID : 12756 FUNCTION: DB2 UDB, bsu security, sqlexLogPluginMessage, probe:20 DATA #1 : String with size, 43 bytes loadAuthidMapper: GetModuleHandle rc = 126

I think the root of this will be down to the new version of Python and pip caching.

What version did you move from and what version are you now on. Is this a Python 2 to Python 3 change? When changing versions, normally you would need to clean pip install all components, but pip does use a cache. Even for components that may need to be compiled, and there is a good chance that Db2 components are being compiled.

So what you will need to do is to re-install the dependancies with

pip install --no-cache-dir

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM