aisstream / issues

7 stars 3 forks source link

Python Example Error - "websockets.exceptions.InvalidMessage: did not receive a valid HTTP response" #20

Closed airqualityanthony closed 1 year ago

airqualityanthony commented 1 year ago

~~Trying to run the python example code - I was originally gettting an SSL cert error as well, but ran the code with ssl=False to try and test if example working generally. Keep getting the following error on not receiving a valid HTTP response. API key valid and checked. ~~


(vehicledata) PS D:\Python Projects> & D:/anaconda3/envs/vehicledata/python.exe "d:/Python Projects/ShipTracking/main.py"
Traceback (most recent call last):
  File "D:\anaconda3\envs\vehicledata\lib\site-packages\websockets\legacy\http.py", line 120, in read_response       
    status_line = await read_line(stream)
  File "D:\anaconda3\envs\vehicledata\lib\site-packages\websockets\legacy\http.py", line 200, in read_line
    raise EOFError("line without CRLF")
EOFError: line without CRLF

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\anaconda3\envs\vehicledata\lib\site-packages\websockets\legacy\client.py", line 139, in read_http_response
    status_code, reason, headers = await read_response(self.reader)
  File "D:\anaconda3\envs\vehicledata\lib\site-packages\websockets\legacy\http.py", line 122, in read_response
    raise EOFError("connection closed while reading HTTP status line") from exc
EOFError: connection closed while reading HTTP status line

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "d:\Python Projects\ShipTracking\main.py", line 24, in <module>
    asyncio.run(connect_ais_stream())
  File "D:\anaconda3\envs\vehicledata\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "D:\anaconda3\envs\vehicledata\lib\asyncio\base_events.py", line 649, in run_until_complete
    return future.result()
  File "d:\Python Projects\ShipTracking\main.py", line 8, in connect_ais_stream
    async with websockets.connect("wss://stream.aisstream.io/v0/stream",ssl=False) as websocket:
  File "D:\anaconda3\envs\vehicledata\lib\site-packages\websockets\legacy\client.py", line 637, in __aenter__
    return await self
  File "D:\anaconda3\envs\vehicledata\lib\site-packages\websockets\legacy\client.py", line 655, in __await_impl_timeout__
    return await self.__await_impl__()
  File "D:\anaconda3\envs\vehicledata\lib\site-packages\websockets\legacy\client.py", line 662, in __await_impl__
    await protocol.handshake(
  File "D:\anaconda3\envs\vehicledata\lib\site-packages\websockets\legacy\client.py", line 323, in handshake
    status_code, response_headers = await self.read_http_response()
  File "D:\anaconda3\envs\vehicledata\lib\site-packages\websockets\legacy\client.py", line 145, in read_http_response
    raise InvalidMessage("did not receive a valid HTTP response") from exc
websockets.exceptions.InvalidMessage: did not receive a valid HTTP response
```~~
airqualityanthony commented 1 year ago

Closing as SSL testing shows it was the SSL issue therefore duplicate of #https://github.com/aisstream/issues/issues/2