Websocket rejected (403) and 404 Client Error

When trying to setup a connection in Python (on my paper trading account), I get the following warning on my MacOS Monterey:
“WARNING:alpaca_trade_api.stream:trading stream websocket error, restarting connection: server rejected WebSocket connection: HTTP 403”

Afterwards, I get the following error:
“requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://paper-api.alpaca.markets/v2/v2/account

I am using the integration with Alpaca from Lumibot in Python 3.12.

Please help, current tips online haven’t yet… :slight_smile:

@BosJelle Not sure what the websocket error would be, I wasn’t able to replicate it. However you appear to be using alpaca_trade_api which is deprecated. There may be some issue with that SDK?

The second issue with the Not Found for url: https://paper-api.alpaca.markets/v2/v2/account error is that there is an extra “/V2” in the URL. Remove that and the URL should work.

@Dan_Whitnable_Alpaca Thank you for the fast response. It appears that Lumibot is still using the alpaca_trade_api, therefore I need to use it as well. (I might switch to Backtrader then?).

Regarding the second issue, in the Alpaca dashboard under ‘API Keys’ - ‘Endpoint’ it states: ‘https://paper-api.alpaca.markets/v2’. If I remove the ‘v2’ in my config.py file I get the following error instead when running my script:
“AttributeError: type object ‘Strategy’ has no attribute ‘broker’”

@BosJelle Not familiar with Lumibot so can’t help too much (sorry). One thing you may want to try when setting the endpoint is to try including then excluding the final backslash. So perhaps https://paper-api.alpaca.markets/ and then https://paper-api.alpaca.markets. Just a thought.