简体   繁体   English

如何在 python 中使用 SQLAlchemy 修复与 db2 的连接?

[英]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.我在使用 SQLAlchemy 连接到 IBM Db2 on Cloud 中的数据库 BLUDB 时遇到问题。 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([]) (ibm_db_dbi.ProgrammingError) ibm_db_dbi::ProgrammingError: Exception('[IBM][CLI Driver] SQL1042C 发生意外的系统错误。SQLSTATE=58004\\r SQLCODE=-1042')(此错误的背景:http://sqlalche .me/e/13/f405) 需要 SQLAlchemy 格式的连接信息,例如:postgresql://username:password@hostname/dbname 或现有连接: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.我查看了ibm上的python db2 文档sqlalchemy 错误消息,但找不到任何地方。

I am working in Jupyterlab locally.我在本地的 Jupyterlab 工作。 I've recently reinstalled Python and Jupyterlab.我最近重新安装了 Python 和 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.我能够在 kaggle 和认知课上成功地在云端运行笔记本。 I am also able to connect and query sqlite3 via python without an issue using my local notebook.我还可以使用本地笔记本通过 python 连接和查询 sqlite3,而不会出现问题。

All the ibm modules and version numbers are the same before and after installation.所有 ibm 模块和版本号在安装前后都相同。 I used requirements.txt for reinstallation.我使用requirements.txt进行重新安装。

In db2diag.log here are the last two entries:在 db2diag.log 中,这里是最后两个条目:

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.06.47.081000-300 I13371F372 LEVEL:警告PID:17500 TID:7808 PROC:python.exe INSTANCE:NODE:000 HOSTNAME:DESKTOP-6FFlex0Pgin, FSKTOP-6FFlex0Pgin, USKTOP-DUIDsqDBFOE7 :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 2020-11-05-14.13.49.282000-300 I13745F373 LEVEL:警告PID:3060 TID:12756 PROC:python.exe INSTANCE:NODE:000 HOSTNAME:DESKTOP-6IDFF6xPlexPlugin,FSKUNCTOPDUIDFF6sqDBEMessage, :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.我认为这将归结为新版本的 Python 和 pip 缓存。

What version did you move from and what version are you now on.你是从哪个版本迁移过来的,现在是哪个版本。 Is this a Python 2 to Python 3 change?这是 Python 2 到 Python 3 的变化吗? When changing versions, normally you would need to clean pip install all components, but pip does use a cache.更改版本时,通常您需要清理 pip install 所有组件,但 pip 确实使用缓存。 Even for components that may need to be compiled, and there is a good chance that Db2 components are being compiled.即使对于可能需要编译的组件,并且很有可能正在编译 Db2 组件。

So what you will need to do is to re-install the dependancies with所以你需要做的是重新安装依赖项

pip install --no-cache-dir

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

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