PIKA AMQPS连接:使用AMQPConnectorAmqphandshakeerror完成的连接尝试

发布于 2025-02-04 06:20:23 字数 1297 浏览 3 评论 0原文

我正在尝试使用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-PROTONsasl_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱花细雨 2025-02-11 06:20:23

我从阅读问题和后来评论中猜测远程端点支持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

静若繁花 2025-02-11 06:20:23

我也有同样的问题;我只是使用pika.urlparameter而不是强制SSL连接:

url_string = "amqps://" + username + ":" + password + "@" + host + ":" + str(port) + "/" + vhost
url_parameter = pika.URLParameters(url_string)
connection =  pika.BlockingConnection(url_parameter)

I had the same issue; I just used the pika.urlParameter instead to force an SSL connection:

url_string = "amqps://" + username + ":" + password + "@" + host + ":" + str(port) + "/" + vhost
url_parameter = pika.URLParameters(url_string)
connection =  pika.BlockingConnection(url_parameter)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文