aisstream / issues

7 stars 3 forks source link

AISStream Connection via Proxy Configuration #39

Closed diegocontla closed 11 months ago

diegocontla commented 11 months ago

I'd like to download AIS data, but I need to configure my proxy. Since the websockets python library doesn't support proxies, I've been using aiohttp. It was working fine for a while until I started encountering the following error: headers=resp.headers, aiohttp.client_exceptions.WSServerHandshakeError: 403, message='Invalid response status', url=URL('wss://stream.aisstream.io/v0/stream')

Here is the complete code: import asyncio import aiohttp import json

from datetime import datetime, timezone

async def connect_ais_stream(): async with aiohttp.ClientSession() as session: async with session.ws_connect("wss://stream.aisstream.io/v0/stream", timeout=60, proxy="http://myproxy") as websocket: subscribe_message = { "APIKey": "mykey", "BoundingBoxes": [ [[49.763226938941635, 0.13749553956120605], [49.971829339138274, 0.36569372458035837]] ], "FilterMessageTypes": ["PositionReport"] }

        subscribe_message_json = json.dumps(subscribe_message)
        await websocket.send_str(subscribe_message_json)

        async for message_json in websocket:
            if isinstance(message_json, aiohttp.WSMessage):
                message_json = message_json.data
            entry = json.loads(message_json)
            print(entry)

if name == "main": asyncio.run(connect_ais_stream())

It appears that AISStream may have blocked this connection. Is there an alternative method for using a proxy to connect to the AISStream service?"
diegocontla commented 11 months ago

Error was in our proxy config. Issue closed