alexgolec / tda-api

A TD Ameritrade API client for Python. Includes historical data for equities and ETFs, options chains, streaming order book data, complex order construction, and more.
https://tda-api.readthedocs.io
MIT License
1.26k stars 336 forks source link

An error occurs when running, see the error attachment #310

Open aniu888 opened 2 years ago

aniu888 commented 2 years ago

Please read the bug submission guidelines before submitting a bug.

Not following guidelines may result in your bug being ignored and/or closed.

Description of Bug

**Code to Reproduce** Paste in the code that causes the bug to occur. [德美利报错.txt](https://github.com/alexgolec/tda-api/files/8767582/default.txt) IMPORTANT: Remember to anonymize your code. Be sure to replace API keys/Client IDs with placeholders. Also, never, ever share the contents of your token file. **Expected Behavior** **Actual Behavior** **Error/Exception Log, If Applicable** See here to learn how to turn on debug logging: https://tda-api.readthedocs.io/en/latest/help.html
alexgolec commented 2 years ago

Please provide demonstration code and a description of the problem. If english isn't your first language, feel free to write the issue in your first language and I'll put it through a translator on my end.

https://tda-api.readthedocs.io/en/latest/help.html#provide-adequate-information

aniu888 commented 2 years ago

请提供演示代码和问题描述。如果英语随时不是您的母语,请使用您的母语编写问题,我将通过翻译完成。

https://tda-api.readthedocs.io/en/latest/help.html#provide-adequate-information


OSError Traceback (most recent call last) ~\AppData\Roaming\Python\Python38\site-packages\httpcore_exceptions.py in map_exceptions(map) 7 try: ----> 8 yield 9 except Exception as exc: # noqa: PIE786

~\AppData\Roaming\Python\Python38\site-packages\httpcore\backends\sync.py in start_tls(self, ssl_context, server_hostname, timeout) 56 self.close() ---> 57 raise exc 58 return SyncStream(sock)

~\AppData\Roaming\Python\Python38\site-packages\httpcore\backends\sync.py in start_tls(self, ssl_context, server_hostname, timeout) 51 self._sock.settimeout(timeout) ---> 52 sock = ssl_context.wrap_socket( 53 self._sock, server_hostname=server_hostname

D:\Program Files\anaconda3\lib\ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session) 499 # ctx._wrap_socket() --> 500 return self.sslsocket_class._create( 501 sock=sock,

D:\Program Files\anaconda3\lib\ssl.py in _create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session) 1039 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets") -> 1040 self.do_handshake() 1041 except (OSError, ValueError):

D:\Program Files\anaconda3\lib\ssl.py in do_handshake(self, block) 1308 self.settimeout(None) -> 1309 self._sslobj.do_handshake() 1310 finally:

OSError: [Errno 0] Error

During handling of the above exception, another exception occurred:

ConnectError Traceback (most recent call last) ~\AppData\Roaming\Python\Python38\site-packages\httpx_transports\default.py in map_httpcore_exceptions() 59 try: ---> 60 yield 61 except Exception as exc: # noqa: PIE-786

~\AppData\Roaming\Python\Python38\site-packages\httpx_transports\default.py in handle_request(self, request) 217 with map_httpcore_exceptions(): --> 218 resp = self._pool.handle_request(req) 219

~\AppData\Roaming\Python\Python38\site-packages\httpcore_sync\connection_pool.py in handle_request(self, request) 252 self.response_closed(status) --> 253 raise exc 254 else:

~\AppData\Roaming\Python\Python38\site-packages\httpcore_sync\connection_pool.py in handle_request(self, request) 236 try: --> 237 response = connection.handle_request(request) 238 except ConnectionNotAvailable:

~\AppData\Roaming\Python\Python38\site-packages\httpcore_sync\http_proxy.py in handle_request(self, request) 254 ) --> 255 connect_response = self._connection.handle_request( 256 connect_request

~\AppData\Roaming\Python\Python38\site-packages\httpcore_sync\connection.py in handle_request(self, request) 85 self._connect_failed = True ---> 86 raise exc 87 elif not self._connection.is_available():

~\AppData\Roaming\Python\Python38\site-packages\httpcore_sync\connection.py in handle_request(self, request) 62 try: ---> 63 stream = self._connect(request) 64

~\AppData\Roaming\Python\Python38\site-packages\httpcore_sync\connection.py in _connect(self, request) 149 with Trace("connection.start_tls", request, kwargs) as trace: --> 150 stream = stream.start_tls(**kwargs) 151 trace.return_value = stream

~\AppData\Roaming\Python\Python38\site-packages\httpcore\backends\sync.py in start_tls(self, ssl_context, server_hostname, timeout) 56 self.close() ---> 57 raise exc 58 return SyncStream(sock)

D:\Program Files\anaconda3\lib\contextlib.py in exit(self, type, value, traceback) 130 try: --> 131 self.gen.throw(type, value, traceback) 132 except StopIteration as exc:

~\AppData\Roaming\Python\Python38\site-packages\httpcore_exceptions.py in map_exceptions(map) 11 if isinstance(exc, from_exc): ---> 12 raise to_exc(exc) 13 raise # pragma: nocover

ConnectError: [Errno 0] Error

The above exception was the direct cause of the following exception:

ConnectError Traceback (most recent call last)

in 14 x3=x1[symbol]['markPercentChangeInDouble']; 15 ---> 16 baojia('BIMI');print(x3);print(x2) in baojia(symbol) 9 10 client = auth.client_from_token_file(token_path, api_key) ---> 11 x1=json.loads(client.get_quotes(symbol).text) 12 13 x2=x1[symbol]['lastPrice'];print(x1[symbol]) ~\AppData\Roaming\Python\Python38\site-packages\tda\client\base.py in get_quotes(self, symbols) 1019 1020 path = '/v1/marketdata/quotes' -> 1021 return self._get_request(path, params) 1022 1023 ########################################################################## ~\AppData\Roaming\Python\Python38\site-packages\tda\client\synchronous.py in _get_request(self, path, params) 16 req_num, dest, LazyLog(lambda: json.dumps(params, indent=4))) 17 ---> 18 resp = self.session.get(dest, params=params) 19 self._log_response(resp, req_num) 20 register_redactions_from_response(resp) ~\AppData\Roaming\Python\Python38\site-packages\httpx\_client.py in get(self, url, params, headers, cookies, auth, follow_redirects, timeout, extensions) 1023 **Parameters**: See `httpx.request`. 1024 """ -> 1025 return self.request( 1026 "GET", 1027 url, ~\AppData\Roaming\Python\Python38\site-packages\authlib\integrations\httpx_client\oauth2_client.py in request(self, method, url, withhold_token, auth, **kwargs) 199 raise MissingTokenError() 200 --> 201 if not self.ensure_active_token(self.token): 202 raise InvalidTokenError() 203 ~\AppData\Roaming\Python\Python38\site-packages\authlib\oauth2\client.py in ensure_active_token(self, token) 249 url = self.metadata.get('token_endpoint') 250 if refresh_token and url: --> 251 self.refresh_token(url, refresh_token=refresh_token) 252 return True 253 elif self.metadata.get('grant_type') == 'client_credentials': ~\AppData\Roaming\Python\Python38\site-packages\authlib\oauth2\client.py in refresh_token(self, url, refresh_token, body, auth, headers, **kwargs) 239 auth = self.client_auth(self.token_endpoint_auth_method) 240 --> 241 return self._refresh_token( 242 url, refresh_token=refresh_token, body=body, headers=headers, 243 auth=auth, **session_kwargs) ~\AppData\Roaming\Python\Python38\site-packages\authlib\oauth2\client.py in _refresh_token(self, url, refresh_token, body, headers, auth, **kwargs) 356 def _refresh_token(self, url, refresh_token=None, body='', headers=None, 357 auth=None, **kwargs): --> 358 resp = self._http_post(url, body=body, auth=auth, headers=headers, **kwargs) 359 360 for hook in self.compliance_hook['refresh_token_response']: ~\AppData\Roaming\Python\Python38\site-packages\authlib\oauth2\client.py in _http_post(self, url, body, auth, headers, **kwargs) 414 415 def _http_post(self, url, body=None, auth=None, headers=None, **kwargs): --> 416 return self.session.post( 417 url, data=dict(url_decode(body)), 418 headers=headers, auth=auth, **kwargs) ~\AppData\Roaming\Python\Python38\site-packages\httpx\_client.py in post(self, url, content, data, files, json, params, headers, cookies, auth, follow_redirects, timeout, extensions) 1114 **Parameters**: See `httpx.request`. 1115 """ -> 1116 return self.request( 1117 "POST", 1118 url, ~\AppData\Roaming\Python\Python38\site-packages\authlib\integrations\httpx_client\oauth2_client.py in request(self, method, url, withhold_token, auth, **kwargs) 204 auth = self.token_auth 205 --> 206 return super(OAuth2Client, self).request( 207 method, url, auth=auth, **kwargs) 208 ~\AppData\Roaming\Python\Python38\site-packages\httpx\_client.py in request(self, method, url, content, data, files, json, params, headers, cookies, auth, follow_redirects, timeout, extensions) 800 extensions=extensions, 801 ) --> 802 return self.send(request, auth=auth, follow_redirects=follow_redirects) 803 804 @contextmanager ~\AppData\Roaming\Python\Python38\site-packages\httpx\_client.py in send(self, request, stream, auth, follow_redirects) 887 auth = self._build_request_auth(request, auth) 888 --> 889 response = self._send_handling_auth( 890 request, 891 auth=auth, ~\AppData\Roaming\Python\Python38\site-packages\httpx\_client.py in _send_handling_auth(self, request, auth, follow_redirects, history) 915 916 while True: --> 917 response = self._send_handling_redirects( 918 request, 919 follow_redirects=follow_redirects, ~\AppData\Roaming\Python\Python38\site-packages\httpx\_client.py in _send_handling_redirects(self, request, follow_redirects, history) 952 hook(request) 953 --> 954 response = self._send_single_request(request) 955 try: 956 for hook in self._event_hooks["response"]: ~\AppData\Roaming\Python\Python38\site-packages\httpx\_client.py in _send_single_request(self, request) 988 989 with request_context(request=request): --> 990 response = transport.handle_request(request) 991 992 assert isinstance(response.stream, SyncByteStream) ~\AppData\Roaming\Python\Python38\site-packages\httpx\_transports\default.py in handle_request(self, request) 216 ) 217 with map_httpcore_exceptions(): --> 218 resp = self._pool.handle_request(req) 219 220 assert isinstance(resp.stream, typing.Iterable) D:\Program Files\anaconda3\lib\contextlib.py in __exit__(self, type, value, traceback) 129 value = type() 130 try: --> 131 self.gen.throw(type, value, traceback) 132 except StopIteration as exc: 133 # Suppress StopIteration *unless* it's the same exception that ~\AppData\Roaming\Python\Python38\site-packages\httpx\_transports\default.py in map_httpcore_exceptions() 75 76 message = str(exc) ---> 77 raise mapped_exc(message) from exc 78 79 ConnectError: [Errno 0] Error
alexgolec commented 2 years ago

Please provide example code to show how this failure was triggered. It would also help to explain what you were attempting to do when you encountered this failure.

aniu888 commented 2 years ago

请在发生此故障时如何触发。当您也显示此故障时,这将解释您正在尝试提供的示例。

The above problem occurs when I use my own computer. I can use the server computer normally.

The example is as follows, I have done error handling, so no error is reported, but the quotation result will not be displayed

from tda import auth, client import requests import json

def baojia(symbol): global x2,x3,x4 token_path =r'e:\python\token.pickle' api_key = '****' # api_key is_error = 1 while is_error == 1: try: client = auth.client_from_token_file(token_path, api_key) x1=json.loads(client.get_quotes(symbol).text) is_error = 0 except: print('An error occurred') is_error = 1 x2=x1[symbol]['lastPrice'];print(x1[symbol]) x3=x1[symbol]['markPercentChangeInDouble']; x4=x1[symbol]['totalVolume']; baojia('TYDEV');print(x3);print(x2);print(x4)