akfamily / akshare

AKShare is an elegant and simple financial data interface library for Python, built for human beings! 开源财经数据接口库
https://akshare.akfamily.xyz
MIT License
8.96k stars 1.84k forks source link

fund_etf_hist_em 接口异常 #5090

Closed wuyulong0931 closed 1 month ago

wuyulong0931 commented 1 month ago

报错信息如下:

TimeoutError Traceback (most recent call last) File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connection.py:196, in HTTPConnection._new_conn(self) 195 try: --> 196 sock = connection.create_connection( 197 (self._dns_host, self.port), 198 self.timeout, 199 source_address=self.source_address, 200 socket_options=self.socket_options, 201 ) 202 except socket.gaierror as e:

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\util\connection.py:85, in create_connection(address, timeout, source_address, socket_options) 84 try: ---> 85 raise err 86 finally: 87 # Break explicitly a reference cycle

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\util\connection.py:73, in create_connection(address, timeout, source_address, socket_options) 72 sock.bind(source_address) ---> 73 sock.connect(sa) 74 # Break explicitly a reference cycle

TimeoutError: timed out

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

ConnectTimeoutError Traceback (most recent call last) File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connectionpool.py:789, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, response_kw) 788 # Make the request on the HTTPConnection object --> 789 response = self._make_request( 790 conn, 791 method, 792 url, 793 timeout=timeout_obj, 794 body=body, 795 headers=headers, 796 chunked=chunked, 797 retries=retries, 798 response_conn=response_conn, 799 preload_content=preload_content, 800 decode_content=decode_content, 801 response_kw, 802 ) 804 # Everything went great!

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connectionpool.py:490, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length) 489 new_e = _wrap_proxy_error(new_e, conn.proxy.scheme) --> 490 raise new_e 492 # conn.request() calls http.client.*.request, not the method in 493 # urllib3.request. It also calls makefile (recv) on the socket.

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connectionpool.py:466, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length) 465 try: --> 466 self._validate_conn(conn) 467 except (SocketTimeout, BaseSSLError) as e:

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connectionpool.py:1095, in HTTPSConnectionPool._validate_conn(self, conn) 1094 if conn.is_closed: -> 1095 conn.connect() 1097 # TODO revise this, see https://github.com/urllib3/urllib3/issues/2791

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connection.py:615, in HTTPSConnection.connect(self) 614 sock: socket.socket | ssl.SSLSocket --> 615 self.sock = sock = self._new_conn() 616 server_hostname: str = self.host

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connection.py:205, in HTTPConnection._new_conn(self) 204 except SocketTimeout as e: --> 205 raise ConnectTimeoutError( 206 self, 207 f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 208 ) from e 210 except OSError as e:

ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x000001A8CD1E27D0>, 'Connection to push2his.eastmoney.com timed out. (connect timeout=15)')

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

MaxRetryError Traceback (most recent call last) File c:\Users\WYL\miniconda3\Lib\site-packages\requests\adapters.py:589, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies) 588 try: --> 589 resp = conn.urlopen( 590 method=request.method, 591 url=url, 592 body=request.body, 593 headers=request.headers, 594 redirect=False, 595 assert_same_host=False, 596 preload_content=False, 597 decode_content=False, 598 retries=self.max_retries, 599 timeout=timeout, 600 chunked=chunked, 601 ) 603 except (ProtocolError, OSError) as err:

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connectionpool.py:843, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw) 841 new_e = ProtocolError("Connection aborted.", new_e) --> 843 retries = retries.increment( 844 method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2] 845 ) 846 retries.sleep()

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\util\retry.py:519, in Retry.increment(self, method, url, response, error, _pool, _stacktrace) 518 reason = error or ResponseError(cause) --> 519 raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 521 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)

MaxRetryError: HTTPSConnectionPool(host='push2his.eastmoney.com', port=443): Max retries exceeded with url: /api/qt/stock/kline/get?fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61%2Cf116&ut=7eea3edcaed734bea9cbfc24409ed989&klt=101&fqt=2&beg=20240701&end=20240731&_=1623766962675&secid=1.560030 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000001A8CD1E27D0>, 'Connection to push2his.eastmoney.com timed out. (connect timeout=15)'))

During handling of the above exception, another exception occurred:

ConnectTimeout Traceback (most recent call last) Cell In[4], line 14 12 fund_hist_data = pd.DataFrame() 13 for fund_code, fund_name in fund_pool.items(): ---> 14 fund_hist_df = ak.fund_etf_hist_em(symbol=fund_code, 15 period="daily", 16 start_date=start_dt, 17 end_date=current_dt, 18 adjust="hfq") 19 fund_hist_df['代码'] = fund_code 20 fund_hist_df['名称'] = fund_name

File c:\Users\WYL\miniconda3\Lib\site-packages\akshare\fund\fund_etf_em.py:265, in fund_etf_hist_em(symbol, period, start_date, end_date, adjust) 263 market_id = code_id_dict[symbol] 264 params.update({"secid": f"{market_id}.{symbol}"}) --> 265 r = requests.get(url, timeout=15, params=params) 266 data_json = r.json() 267 except KeyError:

File c:\Users\WYL\miniconda3\Lib\site-packages\requests\api.py:73, in get(url, params, kwargs) 62 def get(url, params=None, kwargs): 63 r"""Sends a GET request. 64 65 :param url: URL for the new :class:Request object. (...) 70 :rtype: requests.Response 71 """ ---> 73 return request("get", url, params=params, **kwargs)

File c:\Users\WYL\miniconda3\Lib\site-packages\requests\api.py:59, in request(method, url, kwargs) 55 # By using the 'with' statement we are sure the session is closed, thus we 56 # avoid leaving sockets open which can trigger a ResourceWarning in some 57 # cases, and look like a memory leak in others. 58 with sessions.Session() as session: ---> 59 return session.request(method=method, url=url, kwargs)

File c:\Users\WYL\miniconda3\Lib\site-packages\requests\sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 584 send_kwargs = { 585 "timeout": timeout, 586 "allow_redirects": allow_redirects, 587 } 588 send_kwargs.update(settings) --> 589 resp = self.send(prep, **send_kwargs) 591 return resp

File c:\Users\WYL\miniconda3\Lib\site-packages\requests\sessions.py:703, in Session.send(self, request, kwargs) 700 start = preferred_clock() 702 # Send the request --> 703 r = adapter.send(request, kwargs) 705 # Total elapsed time of the request (approximately) 706 elapsed = preferred_clock() - start

File c:\Users\WYL\miniconda3\Lib\site-packages\requests\adapters.py:610, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies) 607 if isinstance(e.reason, ConnectTimeoutError): 608 # TODO: Remove this in 3.0.0: see #2811 609 if not isinstance(e.reason, NewConnectionError): --> 610 raise ConnectTimeout(e, request=request) 612 if isinstance(e.reason, ResponseError): 613 raise RetryError(e, request=request)

ConnectTimeout: HTTPSConnectionPool(host='push2his.eastmoney.com', port=443): Max retries exceeded with url: /api/qt/stock/kline/get?fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61%2Cf116&ut=7eea3edcaed734bea9cbfc24409ed989&klt=101&fqt=2&beg=20240701&end=20240731&_=1623766962675&secid=1.560030 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000001A8CD1E27D0>, 'Connection to push2his.eastmoney.com timed out. (connect timeout=15)'))

albertandking commented 1 month ago

报错信息如下:

TimeoutError Traceback (most recent call last) File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connection.py:196, in HTTPConnection._new_conn(self) 195 try: --> 196 sock = connection.create_connection( 197 (self._dns_host, self.port), 198 self.timeout, 199 source_address=self.source_address, 200 socket_options=self.socket_options, 201 ) 202 except socket.gaierror as e:

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\util\connection.py:85, in create_connection(address, timeout, source_address, socket_options) 84 try: ---> 85 raise err 86 finally: 87 # Break explicitly a reference cycle

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\util\connection.py:73, in create_connection(address, timeout, source_address, socket_options) 72 sock.bind(source_address) ---> 73 sock.connect(sa) 74 # Break explicitly a reference cycle

TimeoutError: timed out

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

ConnectTimeoutError Traceback (most recent call last) File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connectionpool.py:789, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, response_kw) 788 # Make the request on the HTTPConnection object --> 789 response = self._make_request( 790 conn, 791 method, 792 url, 793 timeout=timeout_obj, 794 body=body, 795 headers=headers, 796 chunked=chunked, 797 retries=retries, 798 response_conn=response_conn, 799 preload_content=preload_content, 800 decode_content=decode_content, 801 response_kw, 802 ) 804 # Everything went great!

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connectionpool.py:490, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length) 489 new_e = _wrap_proxy_error(new_e, conn.proxy.scheme) --> 490 raise new_e 492 # conn.request() calls http.client.*.request, not the method in 493 # urllib3.request. It also calls makefile (recv) on the socket.

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connectionpool.py:466, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length) 465 try: --> 466 self._validate_conn(conn) 467 except (SocketTimeout, BaseSSLError) as e:

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connectionpool.py:1095, in HTTPSConnectionPool._validate_conn(self, conn) 1094 if conn.is_closed: -> 1095 conn.connect() 1097 # TODO revise this, see urllib3/urllib3#2791

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connection.py:615, in HTTPSConnection.connect(self) 614 sock: socket.socket | ssl.SSLSocket --> 615 self.sock = sock = self._new_conn() 616 server_hostname: str = self.host

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connection.py:205, in HTTPConnection._new_conn(self) 204 except SocketTimeout as e: --> 205 raise ConnectTimeoutError( 206 self, 207 f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 208 ) from e 210 except OSError as e:

ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x000001A8CD1E27D0>, 'Connection to push2his.eastmoney.com timed out. (connect timeout=15)')

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

MaxRetryError Traceback (most recent call last) File c:\Users\WYL\miniconda3\Lib\site-packages\requests\adapters.py:589, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies) 588 try: --> 589 resp = conn.urlopen( 590 method=request.method, 591 url=url, 592 body=request.body, 593 headers=request.headers, 594 redirect=False, 595 assert_same_host=False, 596 preload_content=False, 597 decode_content=False, 598 retries=self.max_retries, 599 timeout=timeout, 600 chunked=chunked, 601 ) 603 except (ProtocolError, OSError) as err:

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\connectionpool.py:843, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw) 841 new_e = ProtocolError("Connection aborted.", new_e) --> 843 retries = retries.increment( 844 method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2] 845 ) 846 retries.sleep()

File c:\Users\WYL\miniconda3\Lib\site-packages\urllib3\util\retry.py:519, in Retry.increment(self, method, url, response, error, _pool, _stacktrace) 518 reason = error or ResponseError(cause) --> 519 raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 521 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)

MaxRetryError: HTTPSConnectionPool(host='push2his.eastmoney.com', port=443): Max retries exceeded with url: /api/qt/stock/kline/get?fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61%2Cf116&ut=7eea3edcaed734bea9cbfc24409ed989&klt=101&fqt=2&beg=20240701&end=20240731&_=1623766962675&secid=1.560030 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000001A8CD1E27D0>, 'Connection to push2his.eastmoney.com timed out. (connect timeout=15)'))

During handling of the above exception, another exception occurred:

ConnectTimeout Traceback (most recent call last) Cell In[4], line 14 12 fund_hist_data = pd.DataFrame() 13 for fund_code, fund_name in fund_pool.items(): ---> 14 fund_hist_df = ak.fund_etf_hist_em(symbol=fund_code, 15 period="daily", 16 start_date=start_dt, 17 end_date=current_dt, 18 adjust="hfq") 19 fund_hist_df['代码'] = fund_code 20 fund_hist_df['名称'] = fund_name

File c:\Users\WYL\miniconda3\Lib\site-packages\akshare\fund\fund_etf_em.py:265, in fund_etf_hist_em(symbol, period, start_date, end_date, adjust) 263 market_id = code_id_dict[symbol] 264 params.update({"secid": f"{market_id}.{symbol}"}) --> 265 r = requests.get(url, timeout=15, params=params) 266 data_json = r.json() 267 except KeyError:

File c:\Users\WYL\miniconda3\Lib\site-packages\requests\api.py:73, in get(url, params, kwargs) 62 def get(url, params=None, kwargs): 63 r"""Sends a GET request. 64 65 :param url: URL for the new :class:Request object. (...) 70 :rtype: requests.Response 71 """ ---> 73 return request("get", url, params=params, **kwargs)

File c:\Users\WYL\miniconda3\Lib\site-packages\requests\api.py:59, in request(method, url, kwargs) 55 # By using the 'with' statement we are sure the session is closed, thus we 56 # avoid leaving sockets open which can trigger a ResourceWarning in some 57 # cases, and look like a memory leak in others. 58 with sessions.Session() as session: ---> 59 return session.request(method=method, url=url, kwargs)

File c:\Users\WYL\miniconda3\Lib\site-packages\requests\sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 584 send_kwargs = { 585 "timeout": timeout, 586 "allow_redirects": allow_redirects, 587 } 588 send_kwargs.update(settings) --> 589 resp = self.send(prep, **send_kwargs) 591 return resp

File c:\Users\WYL\miniconda3\Lib\site-packages\requests\sessions.py:703, in Session.send(self, request, kwargs) 700 start = preferred_clock() 702 # Send the request --> 703 r = adapter.send(request, kwargs) 705 # Total elapsed time of the request (approximately) 706 elapsed = preferred_clock() - start

File c:\Users\WYL\miniconda3\Lib\site-packages\requests\adapters.py:610, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies) 607 if isinstance(e.reason, ConnectTimeoutError): 608 # TODO: Remove this in 3.0.0: see #2811 609 if not isinstance(e.reason, NewConnectionError): --> 610 raise ConnectTimeout(e, request=request) 612 if isinstance(e.reason, ResponseError): 613 raise RetryError(e, request=request)

ConnectTimeout: HTTPSConnectionPool(host='push2his.eastmoney.com', port=443): Max retries exceeded with url: /api/qt/stock/kline/get?fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61%2Cf116&ut=7eea3edcaed734bea9cbfc24409ed989&klt=101&fqt=2&beg=20240701&end=20240731&_=1623766962675&secid=1.560030 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000001A8CD1E27D0>, 'Connection to push2his.eastmoney.com timed out. (connect timeout=15)'))

请按 issues 模块提交问题