tedchou12 / webull

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

Question about error throwing #315

Closed sullyruss closed 2 years ago

sullyruss commented 2 years ago

Hello,

First I'd like to say thank you. very much for allowing access to this library. I've loved every second working with it. I do; however, have an issue. My program loops each minute. Im able to run it on average 6 hours before it strangely disconnects. Now, this could be an issue with my internet. Im not worried about the D/C. Im simply wanting to catch the connection error exception objection so I can restart my program while I am away. You will see the error message below. Is there anyway I can possibly "try/catch" this error? Or do you know any workarounds or have any other possible solutions to this? Thanks,

-sullyruss

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen httplib_response = self._make_request( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 382, in _make_request self._validate_conn(conn) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn conn.connect() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connection.py", line 411, in connect self.sock = ssl_wrapsocket( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/util/ssl.py", line 449, in ssl_wrap_socket ssl_sock = _ssl_wrap_socketimpl( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/util/ssl.py", line 493, in _ssl_wrap_socket_impl return ssl_context.wrap_socket(sock, server_hostname=server_hostname) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1040, in _create self.do_handshake() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1309, in do_handshake self._sslobj.do_handshake() TimeoutError: [Errno 60] Operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/adapters.py", line 439, in send resp = conn.urlopen( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen retries = retries.increment( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/util/retry.py", line 532, in increment raise six.reraise(type(error), error, _stacktrace) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/packages/six.py", line 769, in reraise raise value.with_traceback(tb) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen httplib_response = self._make_request( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 382, in _make_request self._validate_conn(conn) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn conn.connect() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connection.py", line 411, in connect self.sock = ssl_wrapsocket( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/util/ssl.py", line 449, in ssl_wrap_socket ssl_sock = _ssl_wrap_socketimpl( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/util/ssl.py", line 493, in _ssl_wrap_socket_impl return ssl_context.wrap_socket(sock, server_hostname=server_hostname) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1040, in _create self.do_handshake() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1309, in do_handshake self._sslobj.do_handshake() urllib3.exceptions.ProtocolError: ('Connection aborted.', TimeoutError(60, 'Operation timed out'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/sullyruss/Dropbox/Mac/Desktop/iHedge/iHedge_v0.1/getData.py", line 146, in portfolio = wb.get_portfolio() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/webull/webull.py", line 301, in get_portfolio data = self.get_account() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/webull/webull.py", line 286, in get_account response = requests.get(self._urls.account(self._account_id), headers=headers) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/api.py", line 75, in get return request('get', url, params=params, kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/api.py", line 61, in request return session.request(method=method, url=url, kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/sessions.py", line 542, in request resp = self.send(prep, send_kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/sessions.py", line 655, in send r = adapter.send(request, kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/adapters.py", line 498, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', TimeoutError(60, 'Operation timed out'))

tedchou12 commented 2 years ago

@sullyruss Thanks for the kudos.

For the error part, requests.exceptions.ConnectionError: ('Connection aborted.', TimeoutError(60, 'Operation timed out')), looks like it is an Operation timed out. For any typical error, you could probably try catch, but if it is indeed related to network issue, try catch will not work, you can loop it over for 10x the time and it will still be timed out.

Technically, you can change the timeout tolerance (it looks like 60sec currently?) to see if the situation would alleviate, but again, if it is related to network, you are probably out of luck.

sullyruss commented 2 years ago

@tedchou12 Timeout tolerance. I can do definately something with this concept. Great idea. Thank you.