我正在使用 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,0,1,0,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 身份验证。
关于python - 通过 pyodbc 和 Linux(使用 Docker)访问 i Series AS400 数据库时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67592327/