tedchou12 / webull

Unofficial APIs for Webull.
MIT License
597 stars 183 forks source link

Connection Error #243

Closed bpkum closed 3 years ago

bpkum commented 3 years ago

I am trying to get the bars data in a loop, once every 5 mins... It looks like I have exceeded the max retries... Initially, I was just doing it in a loop (without the 5 mins spacing), it worked fine for a few days, but then I started getting this error... so I spaced the get bars 5 mins apart...but now it fails as soon as I do the first get bars call (even with the 5 mins spacing)... Any help?

Traceback (most recent call last): File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/urllib3/connection.py", line 159, in _new_conn conn = connection.create_connection( File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/urllib3/util/connection.py", line 61, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 953, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 670, in urlopen httplib_response = self._make_request( File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 381, in _make_request self._validate_conn(conn) File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 976, in _validate_conn conn.connect() File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/urllib3/connection.py", line 308, in connect conn = self._new_conn() File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/urllib3/connection.py", line 171, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fa8d4ccce20>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/requests/adapters.py", line 439, in send resp = conn.urlopen( File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 724, in urlopen retries = retries.increment( File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/urllib3/util/retry.py", line 439, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='quotes-gw.webullbroker.com', port=443): Max retries exceeded with url: /api/search/pc/tickers?keyword=SPY&pageIndex=1&pageSize=20&regionId=6 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa8d4ccce20>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/PK/PycharmProjects/webull/main.py", line 130, in returned_bars = bar_creator(ticker, next_date_selection) File "/Users/PK/PycharmProjects/webull/main.py", line 76, in bar_creator transitional_bars = wbl_initializer.get_bars(stock=ticker_selected, interval='m1', count=200, extendTrading=1, File "/Users/PK/PycharmProjects/webull/webull/webull.py", line 1028, in get_bars tId = self.get_ticker(stock) File "/Users/PK/PycharmProjects/webull/webull/webull.py", line 360, in get_ticker response = requests.get(self._urls.stock_id(stock, self._region_code), headers=headers) File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/requests/api.py", line 76, in get return request('get', url, params=params, kwargs) File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/requests/api.py", line 61, in request return session.request(method=method, url=url, kwargs) File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/requests/sessions.py", line 530, in request resp = self.send(prep, send_kwargs) File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/requests/sessions.py", line 643, in send r = adapter.send(request, kwargs) File "/Users/PK/PycharmProjects/webull/venv/lib/python3.9/site-packages/requests/adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='quotes-gw.webullbroker.com', port=443): Max retries exceeded with url: /api/search/pc/tickers?keyword=SPY&pageIndex=1&pageSize=20&regionId=6 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa8d4ccce20>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

Process finished with exit code 1

bpkum commented 3 years ago

Any help?

alexonab commented 3 years ago

The error indicates a network issue. I'd start by opening a couple cmd windows and ping your default gateway in one and the quotes-gw.webullbroker.com site in another. When your script fails, check if you are also dropping ICMP and where. If you really want to understand the network error and who is causing it, then you may need to use Wireshark and look at the raw network traffic.

bpkum commented 3 years ago

Fantastic recommendation.... I was thinking this was an issue in the code or webull was just blocking my IP address... but it turned out to be a broken router... reset my router... looks to be working fine now... thanks again for the advice... @alexonab