如何解决通过 pyodbc 和 Linux使用 Docker访问 i 系列 AS400 数据库时出现问题
我正在使用 Fast API 和 Docker 测试 API。当我加载网页时,它会尝试使用通过 pyodbc 设置的 AS400 连接运行查询。
我从错误开始:pyodbc.InterfaceError: ('28000','[28000] [IBM][System i Access ODBC Driver]Communication link failure. comm rc=8051 - CWBSY1011 - Kerberos client credentials not found
所以我安装了 krb5 并创建了一张票。然后重新加载网页,我遇到的新错误是 pyodbc.InterfaceError: ('28000','[28000] [IBM][System i Access ODBC Driver]Communication link failure. comm rc=8052 - CWBSY1012 - Kerberos service principal not found for system SYSTEM
,其中 SYSTEM 是我的 AS400 系统名称。
有没有其他人遇到过这种情况?似乎 AS400 要求我在连接时使用 Kerberos,但随后我进行了设置,但系统没有 Kerberos 服务主体。
我是否可能需要完全使用 instructions found here 加入域?我开始了这个过程,但是我遇到了一个错误:Failed to join domain: Not enough storage is available to process this command.
尝试运行 net ads join
时,我假设这是由于 Docker 镜像太小了;所以我认为这是不可能的。
这是我的 ODBC.ini 配置文件:
[QDSN_ASW]
Description=ASW
Driver=iSeries Access ODBC Driver
System=192.168.100.1
UserID=user
Password=pass
Naming=0
DefaultLibraries=QGPL
Database=1492BFDD
ConnectionType=2
CommitMode=2
ExtendedDynamic=0
DefaultPkgLibrary=QGPL
DefaultPackage=A/DEFAULT(IBM),2,1,512
AllowDataCompression=1
LibraryView=0
AllowUnsupportedChar=0
ForceTranslation=0
Trace=0
Trusted_Connection=no
AuthenticationType=No Authentication
解决方法
多亏了this post on stackoverflow,我才能解决这个问题。
基本上,我最初构建的数据库连接(如下所示)似乎过于复杂和不必要。
class CommitMode:
NONE = 0 # Commit immediate (*NONE) --> QSQCLIPKGN
CS = 1 # Read committed (*CS) --> QSQCLIPKGS
CHG = 2 # Read uncommitted (*CHG) --> QSQCLIPKGC
ALL = 3 # Repeatable read (*ALL) --> QSQCLIPKGA
RR = 4 # Serializable (*RR) --> QSQCLIPKGL
class ConnectionType:
ReadWrite = 0 # Read/Write (all SQL statements allowed)
ReadCall = 1 # Read/Call (SELECT and CALL statements allowed)
Readonly = 2 # Read-only (SELECT statements only)
def connstr(system,commitmode=None,connectiontype=ConnectionType.Readonly):
_connstr = 'DRIVER=iSeries Access ODBC Driver;'+ \
'SYSTEM='+system+';'+\
'SIGNON=4;CCSID=1208;TRANSLATE=1;'
if commitmode is not None:
_connstr = _connstr + 'CommitMode=' + str(commitmode) + ';'
if connectiontype is not None:
_connstr = _connstr +'ConnectionType=' + str(connectiontype) + ';'
return _connstr
并且我能够将其简化为:
system = f"SYSTEM=AS400;DRIVER=iSeries Access ODBC Driver;SERVER=192.168.100.0;PORT=446;DATABASE=AS400;UID={user};PWD={pw}"
现在,当我构建 Docker 映像并加载网页时,它会立即查询数据库,无需 Kerberos 身份验证。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。