akfamily / akshare

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

ak.stock_us_fundamental接口无法获取数据,连接超时。 接口问题报告 #3204

Closed happyhzq closed 1 year ago

happyhzq commented 1 year ago

描述遇到的问题

  1. 操作系统版本 - Ubuntu
  2. Python 版本-3.8
  3. AKShare 版本-1.7.99
  4. 接口的名称和代码 ak.stock_us_fundamental
  5. 接口报错的截图或代码 timeout
  6. 期望获得的正确结果 返回数据
happyhzq commented 1 year ago

错误代码:


TimeoutError Traceback (most recent call last) File /usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py:703, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 702 # Make the request on the httplib connection object. --> 703 httplib_response = self._make_request( 704 conn, 705 method, 706 url, 707 timeout=timeout_obj, 708 body=body, 709 headers=headers, 710 chunked=chunked, 711 ) 713 # If we're going to release the connection in finally:, then 714 # the response doesn't need to know about the connection. Otherwise 715 # it will also try to release it and we'll have a double-release 716 # mess.

File /usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py:386, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw) 385 try: --> 386 self._validate_conn(conn) 387 except (SocketTimeout, BaseSSLError) as e: 388 # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.

File /usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py:1042, in HTTPSConnectionPool._validate_conn(self, conn) 1041 if not getattr(conn, "sock", None): # AppEngine might not have .sock -> 1042 conn.connect() 1044 if not conn.is_verified:

File /usr/local/lib/python3.8/site-packages/urllib3/connection.py:414, in HTTPSConnection.connect(self) 412 context.load_default_certs() --> 414 self.sock = ssl_wrap_socket( 415 sock=conn, 416 keyfile=self.key_file, 417 certfile=self.cert_file, 418 key_password=self.key_password, 419 ca_certs=self.ca_certs, 420 ca_cert_dir=self.ca_cert_dir, 421 ca_cert_data=self.ca_cert_data, 422 server_hostname=server_hostname, 423 ssl_context=context, 424 tls_in_tls=tls_in_tls, 425 ) 427 # If we're using all defaults and the connection 428 # is TLSv1 or TLSv1.1 we throw a DeprecationWarning 429 # for the host.

File /usr/local/lib/python3.8/site-packages/urllib3/util/ssl_.py:449, in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir, key_password, ca_cert_data, tls_in_tls) 448 if send_sni: --> 449 ssl_sock = _ssl_wrap_socket_impl( 450 sock, context, tls_in_tls, server_hostname=server_hostname 451 ) 452 else:

File /usr/local/lib/python3.8/site-packages/urllib3/util/ssl_.py:493, in _ssl_wrap_socket_impl(sock, ssl_context, tls_in_tls, server_hostname) 492 if server_hostname: --> 493 return ssl_context.wrap_socket(sock, server_hostname=server_hostname) 494 else:

File /usr/local/lib/python3.8/ssl.py:500, in SSLContext.wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session) 494 def wrap_socket(self, sock, server_side=False, 495 do_handshake_on_connect=True, 496 suppress_ragged_eofs=True, 497 server_hostname=None, session=None): 498 # SSLSocket class handles server_hostname encoding before it calls 499 # ctx._wrap_socket() --> 500 return self.sslsocket_class._create( 501 sock=sock, 502 server_side=server_side, 503 do_handshake_on_connect=do_handshake_on_connect, 504 suppress_ragged_eofs=suppress_ragged_eofs, 505 server_hostname=server_hostname, 506 context=self, 507 session=session 508 )

File /usr/local/lib/python3.8/ssl.py:1040, in SSLSocket._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):

File /usr/local/lib/python3.8/ssl.py:1309, in SSLSocket.do_handshake(self, block) 1308 self.settimeout(None) -> 1309 self._sslobj.do_handshake() 1310 finally:

TimeoutError: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

ProtocolError Traceback (most recent call last) File /usr/local/lib/python3.8/site-packages/requests/adapters.py:489, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies) 488 if not chunked: --> 489 resp = conn.urlopen( 490 method=request.method, 491 url=url, 492 body=request.body, 493 headers=request.headers, 494 redirect=False, 495 assert_same_host=False, 496 preload_content=False, 497 decode_content=False, 498 retries=self.max_retries, 499 timeout=timeout, 500 ) 502 # Send the request. 503 else:

File /usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py:787, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 785 e = ProtocolError("Connection aborted.", e) --> 787 retries = retries.increment( 788 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] 789 ) 790 retries.sleep()

File /usr/local/lib/python3.8/site-packages/urllib3/util/retry.py:550, in Retry.increment(self, method, url, response, error, _pool, _stacktrace) 549 if read is False or not self._is_method_retryable(method): --> 550 raise six.reraise(type(error), error, _stacktrace) 551 elif read is not None:

File /usr/local/lib/python3.8/site-packages/urllib3/packages/six.py:769, in reraise(tp, value, tb) 768 if value.traceback is not tb: --> 769 raise value.with_traceback(tb) 770 raise value

File /usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py:703, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 702 # Make the request on the httplib connection object. --> 703 httplib_response = self._make_request( 704 conn, 705 method, 706 url, 707 timeout=timeout_obj, 708 body=body, 709 headers=headers, 710 chunked=chunked, 711 ) 713 # If we're going to release the connection in finally:, then 714 # the response doesn't need to know about the connection. Otherwise 715 # it will also try to release it and we'll have a double-release 716 # mess.

File /usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py:386, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw) 385 try: --> 386 self._validate_conn(conn) 387 except (SocketTimeout, BaseSSLError) as e: 388 # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.

File /usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py:1042, in HTTPSConnectionPool._validate_conn(self, conn) 1041 if not getattr(conn, "sock", None): # AppEngine might not have .sock -> 1042 conn.connect() 1044 if not conn.is_verified:

File /usr/local/lib/python3.8/site-packages/urllib3/connection.py:414, in HTTPSConnection.connect(self) 412 context.load_default_certs() --> 414 self.sock = ssl_wrap_socket( 415 sock=conn, 416 keyfile=self.key_file, 417 certfile=self.cert_file, 418 key_password=self.key_password, 419 ca_certs=self.ca_certs, 420 ca_cert_dir=self.ca_cert_dir, 421 ca_cert_data=self.ca_cert_data, 422 server_hostname=server_hostname, 423 ssl_context=context, 424 tls_in_tls=tls_in_tls, 425 ) 427 # If we're using all defaults and the connection 428 # is TLSv1 or TLSv1.1 we throw a DeprecationWarning 429 # for the host.

File /usr/local/lib/python3.8/site-packages/urllib3/util/ssl_.py:449, in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir, key_password, ca_cert_data, tls_in_tls) 448 if send_sni: --> 449 ssl_sock = _ssl_wrap_socket_impl( 450 sock, context, tls_in_tls, server_hostname=server_hostname 451 ) 452 else:

File /usr/local/lib/python3.8/site-packages/urllib3/util/ssl_.py:493, in _ssl_wrap_socket_impl(sock, ssl_context, tls_in_tls, server_hostname) 492 if server_hostname: --> 493 return ssl_context.wrap_socket(sock, server_hostname=server_hostname) 494 else:

File /usr/local/lib/python3.8/ssl.py:500, in SSLContext.wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session) 494 def wrap_socket(self, sock, server_side=False, 495 do_handshake_on_connect=True, 496 suppress_ragged_eofs=True, 497 server_hostname=None, session=None): 498 # SSLSocket class handles server_hostname encoding before it calls 499 # ctx._wrap_socket() --> 500 return self.sslsocket_class._create( 501 sock=sock, 502 server_side=server_side, 503 do_handshake_on_connect=do_handshake_on_connect, 504 suppress_ragged_eofs=suppress_ragged_eofs, 505 server_hostname=server_hostname, 506 context=self, 507 session=session 508 )

File /usr/local/lib/python3.8/ssl.py:1040, in SSLSocket._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):

File /usr/local/lib/python3.8/ssl.py:1309, in SSLSocket.do_handshake(self, block) 1308 self.settimeout(None) -> 1309 self._sslobj.do_handshake() 1310 finally:

ProtocolError: ('Connection aborted.', TimeoutError(110, 'Connection timed out'))

During handling of the above exception, another exception occurred:

ConnectionError Traceback (most recent call last) Cell In [1], line 3 1 import akshare as ak ----> 3 stock_us_fundamental_df = ak.stock_us_fundamental(symbol="info") 4 print(stock_us_fundamental_df)

File /usr/local/lib/python3.8/site-packages/akshare/stock/stock_us_sina.py:228, in stock_us_fundamental(stock, symbol) 217 """ 218 美股财务指标 219 https://www.macrotrends.net/stocks/stock-screener (...) 225 :rtype: pandas.DataFrame 226 """ 227 url = "https://www.macrotrends.net/stocks/stock-screener" --> 228 r = requests.get(url) 229 temp_text = r.text[ 230 r.text.find("originalData") + 15 : r.text.find("filterArray") - 8 231 ] 232 data_json = json.loads(temp_text)

File /usr/local/lib/python3.8/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 /usr/local/lib/python3.8/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 /usr/local/lib/python3.8/site-packages/requests/sessions.py:587, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 582 send_kwargs = { 583 "timeout": timeout, 584 "allow_redirects": allow_redirects, 585 } 586 send_kwargs.update(settings) --> 587 resp = self.send(prep, **send_kwargs) 589 return resp

File /usr/local/lib/python3.8/site-packages/requests/sessions.py:701, in Session.send(self, request, kwargs) 698 start = preferred_clock() 700 # Send the request --> 701 r = adapter.send(request, kwargs) 703 # Total elapsed time of the request (approximately) 704 elapsed = preferred_clock() - start

File /usr/local/lib/python3.8/site-packages/requests/adapters.py:547, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies) 544 raise 546 except (ProtocolError, OSError) as err: --> 547 raise ConnectionError(err, request=request) 549 except MaxRetryError as e: 550 if isinstance(e.reason, ConnectTimeoutError): 551 # TODO: Remove this in 3.0.0: see #2811

ConnectionError: ('Connection aborted.', TimeoutError(110, 'Connection timed out'))

albertandking commented 1 year ago

4. stock_us_fundamental

目前接口可以正常获取数据;注意数据获取的频率

happyhzq commented 1 year ago

谢谢