yahooquery icon indicating copy to clipboard operation
yahooquery copied to clipboard

Ticker fails when getaddrinfo fails (socket.gaierror [Errno 11002]

Open chfiii opened this issue 3 years ago • 2 comments

Describe the bug Occasional failure (probable when lots of traffic to yahoo.com). Socket hrows exception that is not handled.:

File "C:\Users\chf\Anaconda3\lib\site-packages\urllib3\connection.py", line 160, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw File "C:\Users\chf\Anaconda3\lib\site-packages\urllib3\util\connection.py", line 61, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "C:\Users\chf\Anaconda3\lib\socket.py", line 752, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\chf\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 677, in urlopen chunked=chunked, File "C:\Users\chf\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request self._validate_conn(conn) File "C:\Users\chf\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 978, in _validate_conn conn.connect() File "C:\Users\chf\Anaconda3\lib\site-packages\urllib3\connection.py", line 309, in connect conn = self._new_conn() File "C:\Users\chf\Anaconda3\lib\site-packages\urllib3\connection.py", line 172, in _new_conn self, "Failed to establish a new connection: %s" % e urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x00000237E47755C8>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\chf\Anaconda3\lib\site-packages\requests\adapters.py", line 449, in send timeout=timeout File "C:\Users\chf\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 767, in urlopen **response_kw File "C:\Users\chf\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 767, in urlopen **response_kw File "C:\Users\chf\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 767, in urlopen **response_kw [Previous line repeated 2 more times] File "C:\Users\chf\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 727, in urlopen method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] File "C:\Users\chf\Anaconda3\lib\site-packages\urllib3\util\retry.py", line 439, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='query2.finance.yahoo.com', port=443): Max retries exceeded with url: /v6/finance/quote?lang=en-US&region=US&corsDomain=finance.yahoo.com&symbols=%5EDJI%2C%5EGSPC%2C%5EIXIC%2CAAPL%2CAEP%2CAMGN%2CAMZN%2CARCC%2CBAC%2CBLK%2CBTC-USD%2CC%2CCASH%2CCAT%2CCB%2CCI%2CCL%3DF%2CCSCO%2CCVS%2CCVX%2CDEO%2CDHR%2CDIS%2CEILDX%2CEMB%2CEURUSD%3DX%2CFADMX%2CFAGIX%2CFDCAX%2CFIPDX%2CFLPSX%2CFNMIX%2CFSKAX%2CFSPSX%2CFSRNX%2CFSSNX%2CFXNAX%2CGC%3DF%2CGD%2CGOOG%2CHD%2CHON%2CIBM%2CIGSB%2CINTC%2CJ%2CJNJ%2CJPC%2CJPM%2CK%2CKKR%2CLDLFX%2CLMBS%2CMDLZ%2CMDYG%2CMRK%2CMSFT%2CNAD%2CNKE%2CNSRGY%2CNVHIX%2COHI%2CONEQ%2CORCL%2CPFE%2CPFF%2CPG%2CPHYZX%2CPTY%2CQCOM%2CRTX%2CSLB%2CSPY%2CSYK%2CT%2CTEL%2CTMO%2CUPS%2CUSB%2CV%2CVBK%2CVIGIX%2CVLO%2CVYM%2CVZ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000237E47755C8>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\chf\Finance\curVersion\ntrack.py", line 194, in (times, fsVals) = updateStockPrices(sprices, rtvals[inds], wb, fsVals) File "C:\Users\chf\Finance\curVersion\utilsNtrack.py", line 330, in updateStockPrices val = tic.quotes File "C:\Users\chf\Anaconda3\lib\site-packages\yahooquery\ticker.py", line 427, in quotes return self._get_data("quotes", **{'list_result': True}) File "C:\Users\chf\Anaconda3\lib\site-packages\yahooquery\base.py", line 603, in _get_data urls = self._construct_urls(config, params, **kwargs) File "C:\Users\chf\Anaconda3\lib\site-packages\yahooquery\base.py", line 648, in construct_urls urls = [self.session.get(url=config['path'], params=params)] File "C:\Users\chf\Anaconda3\lib\site-packages\requests\sessions.py", line 543, in get return self.request('GET', url, **kwargs) File "C:\Users\chf\Anaconda3\lib\site-packages\requests\sessions.py", line 530, in request resp = self.send(prep, **send_kwargs) File "C:\Users\chf\Anaconda3\lib\site-packages\requests\sessions.py", line 643, in send r = adapter.send(request, **kwargs) File "C:\Users\chf\Anaconda3\lib\site-packages\yahooquery\utils_init.py", line 48, in send return super(TimeoutHTTPAdapter, self).send(request, **kwargs) File "C:\Users\chf\Anaconda3\lib\site-packages\requests\adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='query2.finance.yahoo.com', port=443): Max retries exceeded with url: /v6/finance/quote?lang=en-US&region=US&corsDomain=finance.yahoo.com&symbols=%5EDJI%2C%5EGSPC%2C%5EIXIC%2CAAPL%2CAEP%2CAMGN%2CAMZN%2CARCC%2CBAC%2CBLK%2CBTC-USD%2CC%2CCASH%2CCAT%2CCB%2CCI%2CCL%3DF%2CCSCO%2CCVS%2CCVX%2CDEO%2CDHR%2CDIS%2CEILDX%2CEMB%2CEURUSD%3DX%2CFADMX%2CFAGIX%2CFDCAX%2CFIPDX%2CFLPSX%2CFNMIX%2CFSKAX%2CFSPSX%2CFSRNX%2CFSSNX%2CFXNAX%2CGC%3DF%2CGD%2CGOOG%2CHD%2CHON%2CIBM%2CIGSB%2CINTC%2CJ%2CJNJ%2CJPC%2CJPM%2CK%2CKKR%2CLDLFX%2CLMBS%2CMDLZ%2CMDYG%2CMRK%2CMSFT%2CNAD%2CNKE%2CNSRGY%2CNVHIX%2COHI%2CONEQ%2CORCL%2CPFE%2CPFF%2CPG%2CPHYZX%2CPTY%2CQCOM%2CRTX%2CSLB%2CSPY%2CSYK%2CT%2CTEL%2CTMO%2CUPS%2CUSB%2CV%2CVBK%2CVIGIX%2CVLO%2CVYM%2CVZ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000237E47755C8>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))

To Reproduce

Trying to price 85 symbols, Not asynchronous,

tic = Ticker(merged) tval = tic.quotes

Expected behavior Gives me quotes

Desktop (please complete the following information):

  • OS: Win 10 Pro, Using Anaconda, python 3.7.9
  • Feeds quote info into Xlwings to update Excel spreadsheet

chfiii avatar Oct 08 '20 18:10 chfiii

How often are you making this request? I haven't run into this problem yet but my guess is that YF is actively blocking the request either because the number of symbols is so great or because of the frequency of your requests is high.

dpguthrie avatar Oct 14 '20 21:10 dpguthrie

That’s possible. I’m hitting it about once a minute with 85 symbols. I had been done that via the main finance.yahoo.com interface without any problem (averaged ~4-5 seconds using 8 parallel processes to get results – your ticker runs it 10 times faster).

Thanks for the follow up!

Charlie

From: Doug [email protected] Sent: Wednesday, October 14, 2020 5:46 PM To: dpguthrie/yahooquery [email protected] Cc: chfiii [email protected]; Author [email protected] Subject: Re: [dpguthrie/yahooquery] Ticker fails when getaddrinfo fails (socket.gaierror [Errno 11002] (#45)

How often are you making this request? I haven't run into this problem yet but my guess is that YF is actively blocking the request either because the number of symbols is so great or because of the frequency of your requests is high.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dpguthrie/yahooquery/issues/45#issuecomment-708677508 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ACX2GP2JBOSETESJXHWOL3LSKYLYJANCNFSM4SJD25SA .

chfiii avatar Oct 14 '20 22:10 chfiii

Most likely a rate limiting issue on the YF side (not much I can do here).

dpguthrie avatar Oct 15 '22 20:10 dpguthrie