aisstream / issues

7 stars 3 forks source link

Unable to run Python Example #2

Closed russell-sealand closed 1 year ago

russell-sealand commented 1 year ago

Following the steps presented for the Python example described here: https://github.com/aisstream/example I get the following traceback error shown at the bottom regarding SSL Certificate expiry.

I have generated an API key from https://aisstream.io/apikeys and inserted it into the code, replacing the dummy key as follows on line 9 (changed the key below for privacy): subscribe_message = {"APIKey": "9b0dcfd81f52c919d886aeb316ea5672231e8321", "BoundingBoxes": [[[-90, -180], [90, 180]]]}

Any ideas as to what the problem is here? Thanks.


PS D:\GitHub\example\python> python main.py Traceback (most recent call last): File "D:\GitHub\example\python\main.py", line 24, in <module> asyncio.run(asyncio.run(connect_ais_stream())) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run return loop.run_until_complete(main) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 641, in run_until_complete return future.result() File "D:\GitHub\example\python\main.py", line 8, in connect_ais_stream async with websockets.connect("wss://stream.aisstream.io/v0/stream") as websocket: File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\websockets-10.4-py3.10-win-amd64.egg\websockets\legacy\client.py", line 642, in __aenter__ return await self File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\websockets-10.4-py3.10-win-amd64.egg\websockets\legacy\client.py", line 659, in __await_impl_timeout__ return await asyncio.wait_for(self.__await_impl__(), self.open_timeout) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py", line 528, in data_received ssldata, appdata = self._sslpipe.feed_ssldata(data) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py", line 188, in feed_ssldata self._sslobj.do_handshake() File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 974, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)

aisstream commented 1 year ago

From reading about the exception, this issue appears to indicate that our ssl certificate that we use for our websocket service has expired. Furthermore I I have just now verified that our certs are not expired and was able to run the python example in my own python environment 3.9 with no errors. This leads me to believe it is not an error with the service on our end.

Your python version/environment may be rejecting our cert authority with is lets encrypt as described by this stack overflow issue https://stackoverflow.com/questions/72858917/python-requests-throws-sslcertverificationerror-with-lets-encrypt-certificates. It is possible to disable the ssl verification by following the documentation here.

We will attempt to create an example for you with SSL disabled over the coming days.

russell-sealand commented 1 year ago

Thanks for the quick response.

I have now tested the exact same code on my personal computer (also with Python 3.10) rather than my work one and it works as expected. The issue is therefore probably due to a security restriction our IT company has in-place (possibly Bitdefender Endpoint).

I would be interested to read an example with SSL disabled, thank you.

aisstream commented 1 year ago

Issue action items:

aisstream commented 1 year ago

SSL example is now available here