1
votes

I'm trying to use python 2.7 qpid proton (0.17.0) on Debian 4.8.4-1 on google cloud to connect to the service AMQPS 1.0 endpoints on an Azure IoT hub.

I'm using a shared access policy and a SAS token pair (which successfully work in ampq net lite under C#) for SASL PLAIN. For azure iothub, you reference the shared access policy as the username in the format [email protected]

When I use these (obfuscated) credentials with qpid proton as follows

import sys
from proton import Messenger, Message

base = "amqps://[email protected]:SharedAccessSignature sr=HubName.azure-devices.net%2fmessages&sig=PERCENT_ENCODED_SIG&se=1493454429&st=1490861529&[email protected]:5671"

entityName = "/messages/servicebound/feedback"

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

I get the following error

(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

The final error message looks like parsing of the connection string is being mangled (on a very quick look, pni_default_rewrite in qpid-proton/messenger.c appears to use the first occurrence of @ to split the connection string which could be the problem)

However, I'm new to AMQP and proton, so before I raise a bug, want to check whether others have successfully use proton to iothub, or if I've missed something??

1
Do you forget the double quotes of variable base, like this: base = "amqps://..." ?Rita Han
No - they just got lost in writing the questionCharlieBird
Which tutorial did you follow? Have you check this? Note the address format.Rita Han

1 Answers

0
votes

You need to encode amqp username and password.

[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

The server name should be HubName.azure-devices.net:5671, but as you can see in error message, server name changed to sas.root.HubName, SharedAccessSignature sr=HubName.azure-devices.net%2fmessages&sig=PERCENT_ENCODED_SIG&se=1493454429&st=149086152 9&[email protected]:5671