首页 > 解决方案 > 无法通过 python 3 的 pymqi 版本使用 SSL 连接到公共队列

问题描述

我已经设法使用以下 python 代码与 Python2 的旧 pymqi 版本建立了与公共队列的连接:

import logging

import pymqi

logging.basicConfig(level=logging.INFO)

queue_manager = 'QM1'
channel = 'BZU.UAT.CHNL'
host = '245.274.46.56'
port = '1416'
queue_name = 'BZU.UAT.QUEUE'
conn_info = '%s(%s)' % (host, port)
ssl_cipher_spec = 'TLS_RSA_WITH_3DES_EDE_CBC_SHA'
key_repo_location = 'D:\\App\\BZU\\keydb\\key'
message = 'Hello from Python!'

cd = pymqi.CD()
cd.ChannelName = channel
cd.ConnectionName = conn_info
cd.ChannelType = pymqi.CMQC.MQCHT_CLNTCONN
cd.TransportType = pymqi.CMQC.MQXPT_TCP
cd.SSLCipherSpec = ssl_cipher_spec
cd.UserIdentifier = 'BZU'
cd.Password = ''

sco = pymqi.SCO()
sco.KeyRepository = key_repo_location

qmgr = pymqi.QueueManager(None)
qmgr.connect_with_options(queue_manager, cd, sco)

put_queue = pymqi.Queue(qmgr, queue_name)
put_queue.put(message)

get_queue = pymqi.Queue(qmgr, queue_name)
logging.info('Here is the message again: [%s]' % get_queue.get())

put_queue.close()
get_queue.close()
qmgr.disconnect()

不幸的是,此代码不适用于 Python 3 的 pymqi 版本 1.9.3。在这种情况下,我收到以下错误消息:

Traceback (most recent call last):
  File ".\mq_conn_with_ssl.py", line 33, in <module>
    qmgr.connect_with_options(queue_manager, cd, sco)
  File "D:\App\BZU\arn-basis-common\py\pymqi\__init__.py", line 1347, in connect_with_options
    raise MQMIError(rv[1], rv[2])
pymqi.MQMIError: MQI Error. Comp: 2, Reason 2393: FAILED: MQRC_SSL_INITIALIZATION_ERROR

我必须将此代码中的所有字符串转换为字节,因为程序要求所有字符串为字节。例子:

queue_manager = b'QM1'


在您所说的评论中,您在AMQERR01.LOG文件中发现了以下错误:

AMQ9716: Remote SSL certificate revocation status check failed for channel 'BZU.UAT.CHNL'.

标签: python-3.xibm-mqpymqi

解决方案


比较mqclient.ini您的工作服务器和非工作服务器上的文件,以SSL:了解导致 OCSP 检查失败的节中的差异。

mqclient.ini文件的位置可以在 IBM MQ 知识中心页面IBM MQ>Configuring>Configuring connection between server and clients>Configuring a client using a configuration file>Location of the client configuration file中找到。见摘要如下:

  1. 环境变量指定的位置MQCLNTCF
  2. 应用程序当前工作目录中名为 mqclient.ini 的文件。
  3. 适用于 Windows、UNIX 和 Linux 系统的 IBM MQ 数据目录中名为 mqclient.ini 的文件。
  4. 一个名为 mqclient.ini 的文件位于适合平台的标准目录中,并且可供用户访问:

可以在 IBM MQ 知识中心页面IBM MQ>Configuring>Configuring connection between server and clients>Configuring a client using a configuration file>SSL stanza of the client configuration file 中SSL找到有关 节的文档。见摘要如下:mqclient.ini

OCSPAuthentication = 可选 | 必填 | 警告

OCSPCheckExtensions = 是 | 不

SSLHTTPProxyName = 字符串


推荐阅读