Closed MkKiefer closed 1 year ago
It looks like the default port for amqp over websocket is not handled correctly.
It is possible to set the port in the auth (SASLPlain
) object directly.
That is the workaround that i now use:
auth = uamqp.authentication.SASLPlain(
hostname="<hostname>",
username="<username>",
password="<password>",
port=443,
transport_type=uamqp.TransportType.AmqpOverWebsocket
)
client = uamqp.SendClient(uri, auth, debug=True, transport_type=uamqp.TransportType.AmqpOverWebsocket)
Closing this issue as the PR is merged. Thank you @MkKiefer
Amqp over websocket connection error
UAMQP Package Version: 1.6.3
Operating System: Windows / WSL / Docker
Python Version: 3.8, 3.9, 3.10
Describe the bug:
Connection to IoTHub failed with transport type:
amqp.TransportType.AmqpOverWebsocket
at versions > v1.2.13Currently using the version: v1.2.13 (the last version where the amqp over ws works for me) and trying to update to v1.6.3 The websocket connection is needed because some firewalls are blocking the plain amqp connection This behavior is the same on multiple platforms:
The same error ocurred with the async and sync client.
Logg message
### Logs ```PYTHON 2023-01-16 10:11:32,134 uamqp.c_uamqp DEBUG Creating SASL Mechanism 2023-01-16 10:11:32,138 uamqp.client DEBUG Opening client connection. 2023-01-16 10:11:32,138 uamqp DEBUG Initializing platform. 2023-01-16 10:11:32,138 uamqp.connection INFO Connection b'7475125f-f01a-4a3a-936c-7fdc8c69f607' state changed fromSystem / dependency's
WSL
Test inside docker container with different build environments:
RaspberryPi 4 / RaspberryPi3b+
Test inside docker container with different build environments:
Windows:
Python on Windows:
pip
To Reproduce
Baltimore CyberTrust root
but also tested withDigiCert Global G2
)Try to connect and send a message with
uamqp.SendClient(uri, debug=True, transport_type=uamqp.TransportType.AmqpOverWebsocket)
(see example)Example code
### Send to IoTHub ```PYTHON logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)s >> %(message)s', datefmt='%Y-%m-%d %H:%M:%S')def generate_connection_uri(config): """ Generates the amqp enpoint url depending on the provided connection string :return: amqp endpoint """ username = '{device_id}@sas.{iot_hub_name}'.format( device_id=config["device_id"], iot_hub_name=config["hub_name"])
def send_iot_hub(config): data = b"test message" message = uamqp.Message(data) uri = generate_connection_uri(config)
if name == 'main': config = {} REG_EXP_CONNECTION_STRING = r"^HostName=(.).azure-devices.net;DeviceId=(.);SharedAccessKey=(.*)$" m_obj = re.match(REG_EXP_CONNECTION_STRING, os.environ['CONNECTION_STRING']) config['hub_address'] = m_obj.group(1) + ".azure-devices.net" config['hub_name'] = m_obj.group(1) config['device_id'] = m_obj.group(2) config['device_key'] = m_obj.group(3) print(config)