Hello,
I’m using a Python script to connect to the Alpaca Market paper API (it is the same think to API) from pythonanywhere via WebSocket, but unfortunately, I’m encountering error number 111, connectionRefusedError.
The code works fine when I run it from my personal computer, but when I execute it from PythonAnywhere,
PythonAnywhere is server linked to Anaconda. it’s very sure.
I get this error. Here’s the code:
########
import configPAP as config
import datetime
from alpaca_trade_api.common import URL
from alpaca_trade_api.stream import Stream
async def trade_callback(t):
print('trade', t)
time.sleep(50)
async def quote_callback(q):
print('quote', q)
# Initiate Class Instance
stream = Stream(config.API_KEY,
config.SECRET_KEY,
base_url=URL('https://paper-api.alpaca.markets'),
data_feed='iex', # <- replace to 'sip' if you have PRO subscription
websocket_params= {'ping_interval': 50},)
# subscribing to event
stream.subscribe_trades(trade_callback, 'AAPL')
stream.subscribe_quotes(quote_callback, 'IBM')
stream.run()
" AND here’s the encountered error : "
error during websocket communication:
[Errno 111] Connect call failed ('38.122.35.99', 443)
Traceback (most recent call last):
File "/home/lco75005/.local/lib/python3.9/site-packages/alpaca_trade_api/stream.py", line 251, in _run_forever
await self._start_ws()
File "/home/lco75005/.local/lib/python3.9/site-packages/alpaca_trade_api/stream.py", line 104, in _start_ws
await self._connect()
File "/home/lco75005/.local/lib/python3.9/site-packages/alpaca_trade_api/stream.py", line 79, in _connect
self._ws = await websockets.connect(
File "/home/lco75005/.local/lib/python3.9/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.9/asyncio/tasks.py", line 481, in wait_for
return fut.result()
File "/home/lco75005/.local/lib/python3.9/site-packages/websockets/legacy/client.py", line 663, in __await_impl__
_transport, _protocol = await self._create_connection()
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1056, in create_connection
raise exceptions[0]
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1041, in create_connection
sock = await self._connect_sock(
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 955, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 502, in sock_connect
return await fut
File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 537, in _sock_connect_cb
raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('38.122.35.99', 443)"
So, in your opinion, what’s wrong here ? the code works from my personnal computer but not from PAW (pythonanywhere) and i don’t know
Thank you for your responses.