通过pyodbc和Linux(使用Docker)访问i系列AS400数据库时遇到问题

2024-09-29 10:23:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用FastAPI和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

Tags: docker网页accessdriver错误linkkerberossystem
1条回答
网友
1楼 · 发布于 2024-09-29 10:23:31

多亏了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映像并加载web页面时,它会立即查询数据库,而不需要Kerberos身份验证

相关问题 更多 >