PIKA AMQPS连接:使用AMQPConnectorAmqphandshakeerror完成的连接尝试
我正在尝试使用pika
连接到AMQPS服务(我没有配置访问或获得证书的方法)。
这是代码:
import pika
from urllib.parse import urlparse
import ssl
credentials = pika.PlainCredentials(username, password)
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.verify_mode = ssl.CERT_NONE
ssl_options=pika.SSLOptions(context)
params = pika.ConnectionParameters(
host=url.hostname,
port=url.port,
credentials=credentials,
ssl_options=ssl_options
)
connection = pika.BlockingConnection(params)
channel = connection.channel() # start a channel
每次我尝试执行此操作时,它都会失败:
ERROR:pika.adapters.utils.connection_workflow:AMQPConnector - reporting failure:
AMQPConnectorAMQPHandshakeError:
IncompatibleProtocolError: The protocol returned by the server is not supported:
('StreamLostError:
("Stream connection lost: SSLEOFError(8, \'EOF occurred in violation of protocol (_ssl.c:2633)\')",)',)
不幸的是,我不知道服务器返回哪个协议。
使用QPID-PROTON
与sasl_enabled:true
选项集,它可以无问题。
from proton import Message
from proton.utils import BlockingConnection
conn = BlockingConnection(
url,
password=password,
user=username,
sasl_enabled=True,
)
但是,我还没有找到使用pika
来完成此操作的方法。
I am trying to use pika
connect to a AMQPS-Service (to which I have no config access or a way to get the certificates).
Here's the code:
import pika
from urllib.parse import urlparse
import ssl
credentials = pika.PlainCredentials(username, password)
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.verify_mode = ssl.CERT_NONE
ssl_options=pika.SSLOptions(context)
params = pika.ConnectionParameters(
host=url.hostname,
port=url.port,
credentials=credentials,
ssl_options=ssl_options
)
connection = pika.BlockingConnection(params)
channel = connection.channel() # start a channel
Everytime I try to execute this though, it fails with:
ERROR:pika.adapters.utils.connection_workflow:AMQPConnector - reporting failure:
AMQPConnectorAMQPHandshakeError:
IncompatibleProtocolError: The protocol returned by the server is not supported:
('StreamLostError:
("Stream connection lost: SSLEOFError(8, \'EOF occurred in violation of protocol (_ssl.c:2633)\')",)',)
Unfortunately, I do not know which protocol is returned by the server.
Using qpid-proton
with the sasl_enabled: True
option set, it works without any issues.
from proton import Message
from proton.utils import BlockingConnection
conn = BlockingConnection(
url,
password=password,
user=username,
sasl_enabled=True,
)
However, I haven't found a way to do this with pika
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从阅读问题和后来评论中猜测远程端点支持AMQP 1.0,而PIKA客户端似乎仅支持0.9.1草案AMQP规格,这会使返回的错误敏感。您需要使用能够使用ISO规格AMQP 1.0标准的客户端
My guess from reading the question and later comments the remote endpoint supports AMQP 1.0 and the Pika client appears to support only the 0.9.1 draft AMQP spec which would make the returned error sensible. You'd need to use a client capable of using the ISO spec AMQP 1.0 standard
我也有同样的问题;我只是使用
pika.urlparameter
而不是强制SSL连接:I had the same issue; I just used the
pika.urlParameter
instead to force an SSL connection: