gpt4 book ai didi

azure - Proton 与 azure iot hub amqp 端点的连接

转载 作者:行者123 更新时间:2023-12-03 04:26:14 25 4
gpt4 key购买 nike

我正在尝试在 Google Cloud 上的 Debian 4.8.4-1 上使用 python 2.7 qpid proton (0.17.0) 连接到 Azure IoT 中心上的服务 AMQPS 1.0 端点。

我正在为 SASL PLAIN 使用共享访问策略和 SAS token 对(在 C# 下的 ampq net lite 中成功工作)。对于 azure iothub,您可以将共享访问策略引用为格式为 [email protected] 的用户名。

当我将这些(混淆的)凭据与 qpid proton 一起使用时,如下所示

import sys
from proton import Messenger, Message

base = "amqps://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="452c2a312d30272a322b2037053624366b372a2a316b0d30270b242820" rel="noreferrer noopener nofollow">[email protected]</a>:SharedAccessSignature sr=HubName.azure-devices.net%2fmessages&sig=PERCENT_ENCODED_SIG&se=1493454429&st=1490861529&<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="41322a2f7c282e352934232e362f2433010934230f202c246f203b3433246c252437282224326f2f2435" rel="noreferrer noopener nofollow">[email protected]</a>:5671"

entityName = "/messages/servicebound/feedback"

messenger = Messenger()
messenger.subscribe("%s%s" % ( base, entityName))
messenger.start()

我收到以下错误

(debug print of connection string being passed) amqps://[email protected]:SharedAccessSignature sr=HubName.azure-devices.net%2fmessages&sig=PERCENT_ENCODED_SIG&se=1493454429&st=1490861529&[email protected]:5671

Traceback (most recent call last): File "readProton2.py", line 27, in messenger.subscribe("%s%s" % ( base, entityName)) File "/usr/lib/python2.7/dist-packages/proton/__init__.py", line 496, in subscribe self._check(pn_error_code(pn_messenger_error(self._mng))) File "/usr/lib/python2.7/dist-packages/proton/__init__.py", line 300, in _check raise exc("[%s]: %s" % (err, pn_error_text(pn_messenger_error(self._mng))))

proton.MessengerException: [-2]: CONNECTION ERROR (sas.root.HubName:SharedAccessSignature sr=HubName.azure-devices.net%2fmessages&sig=PERCENT_ENCODED_SIG&se=1493454429&st=1490861529&[email protected]:5671): getaddrinfo(sas.root.HubName, SharedAccessSignature sr=HubName.azure-devices.net%2fmessages&sig=PERCENT_ENCODED_SIG&se=1493454429&st=149086152 9&[email protected]:5671): Servname not supported for ai_socktype

最后的错误消息看起来像是连接字符串的解析正在被破坏(快速查看一下,qpid-proton/messenger.c 中的 pni_default_rewrite 似乎使用第一次出现的 @ 来分割连接字符串,这可能是问题)

但是,我对 AMQP 和 proton 还很陌生,所以在提出错误之前,想检查其他人是否已成功使用 proton 到 iothub,或者我是否遗漏了某些内容?

最佳答案

您需要对 amqp 用户名和密码进行编码。

[email protected]

iothubowner%40sas.root.HubName

SharedAccessSignature sr=HubName.azure-devices.net%2fmessages&sig=PERCENT_ENCODED_SIG&se=1493454429&st=1490861529&skn=iothubowner

SharedAccessSignature%20sr%3DHubName.azure-devices.net%252fmessages%26sig%3DPERCENT_ENCODED_SIG%26se%3D1493454429%26st%3D1490861529%26skn%3Diothubowner

服务器名称应为HubName.azure-devices.net:5671 ,但正如您在错误消息中看到的,服务器名称更改为 sas.root.HubName, SharedAccessSignature sr=HubName.azure-devices.net%2fmessages&sig=PERCENT_ENCODED_SIG&se=1493454429&st=149086152 9&<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="34475f5a095d5b405c41565b435a5146747c41567a5559511a554e414651195051425d5751471a5a5140" rel="noreferrer noopener nofollow">[email protected]</a>:5671

关于azure - Proton 与 azure iot hub amqp 端点的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43117754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com