繁体   English   中英

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

[英]Trouble with access to i Series AS400 database via pyodbc and Linux (using Docker)

我正在使用快速 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 服务主体。

我是否可能需要使用 此处的说明完全加入域? 我开始了这个过程,但是我遇到了一个错误: 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

由于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 身份验证。

暂无
暂无

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

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