What product/components do you use and which version/fix level are you on?
Cumulocity IoT 1015.0.278
Is your question related to the free trial, or to a production (customer) instance?
prduction: xy.cumulocity.com
What are you trying to achieve? Please describe it in detail.
Running a Python Microservice on Cumulocity IoT which uses the Notification 2.0 API
Therefore i use the websockets library with asyncio in a seperate thread, the main thread is starting a flask server.
When i run a similar python script on my local machine and connect it to the same Cumulocity IoT Tenant, it works.
This is the relevant part of the code, its the continuous listening for incoming messages:
async def listen(self, callback: callable):
async with websockets.connect(
f"wss://{url}/notification2/consumer/?token={self.token}"
) as websocket:
print(f"Websocket connected: {str(websocket)}")
async for message in websocket:
print("Received message: {}".format(message))
await callback(message)
Do you get any error messages? Please provide a full error message screenshot and log file.
From the log in
Traceback (most recent call last):
File "//main.py", line 82, in <module>
listen_websocket(handle_alarms)
File "//main.py", line 64, in listen_websocket
asyncio.run(alarm_subscription.listen(callback)) # blocking
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/API/subscribe.py", line 79, in listen
async with websockets.connect(
File "/usr/local/lib/python3.11/site-packages/websockets/legacy/client.py", line 642, in __aenter__
return await self
^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/websockets/legacy/client.py", line 659, in __await_impl_timeout__
return await asyncio.wait_for(self.__await_impl__(), self.open_timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/tasks.py", line 479, in wait_for
return fut.result()
^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/websockets/legacy/client.py", line 663, in __await_impl__
_transport, _protocol = await self._create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1112, in create_connection
transport, protocol = await self._create_connection_transport(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1145, in _create_connection_transport
await waiter
File "/usr/local/lib/python3.11/asyncio/sslproto.py", line 574, in _on_handshake_complete
raise handshake_exc
File "/usr/local/lib/python3.11/asyncio/sslproto.py", line 556, in _do_handshake
self._sslobj.do_handshake()
File "/usr/local/lib/python3.11/ssl.py", line 979, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:992)
Have you installed all the latest fixes for the products and systems you are using?
Cumulocity IoT 1015.0.278