python-3.x - 无法通过 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'.
解决方案
比较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中找到。见摘要如下:
- 环境变量指定的位置
MQCLNTCF
。- 应用程序当前工作目录中名为 mqclient.ini 的文件。
- 适用于 Windows、UNIX 和 Linux 系统的 IBM MQ 数据目录中名为 mqclient.ini 的文件。
- 一个名为 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 = 字符串
推荐阅读
- jquery - 基于 div 位置的颜色填充导航项目
- bash - 从数字范围生成自定义字符串并将其保存到 bash 中的数组
- javascript - 了解异步与同步 javascript
- reactjs - React 生成的表格中的文本区域更改无法正常工作
- python - 如何从下拉选择中获取数据并将其显示在同一个 HTML 页面上?姜戈
- sql - 在 SQL 中将持续时间转换为秒
- r - R:带有 scale_color_manual 错误的 ggplot geom_hline 自定义图例
- macos - 将 Rust 应用程序从 macOS 交叉编译到 Raspberry Pi 2 时,“与 arm-linux-gnueabihf-gcc 的链接失败”
- python - Python rq 包中的队列类、工作者类、作业类是什么
- c# - 使用各种参数在 C# 中从 cmd.exe 运行 .bat 文件