我使用python请求get()函数通过API访问数据,多次获取数据后,发生了异常:“错误的握手:SysCallError(-1,'意外的EOF')”
以下是整个异常信息:
---------------------------------------------------------------------------
SysCallError Traceback (most recent call last)
D:\Users\64249\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
455 try:
--> 456 cnx.do_handshake()
457 except OpenSSL.SSL.WantReadError:
D:\Users\64249\Anaconda3\lib\site-packages\OpenSSL\SSL.py in do_handshake(self)
1914 result = _lib.SSL_do_handshake(self._ssl)
-> 1915 self._raise_ssl_error(self._ssl, result)
1916
D:\Users\64249\Anaconda3\lib\site-packages\OpenSSL\SSL.py in _raise_ssl_error(self, ssl, result)
1639 raise SysCallError(errno, errorcode.get(errno))
-> 1640 raise SysCallError(-1, "Unexpected EOF")
1641 else:
SysCallError: (-1, 'Unexpected EOF')
During handling of the above exception, another exception occurred:
SSLError Traceback (most recent call last)
D:\Users\64249\Anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
593 if is_new_proxy_conn:
--> 594 self._prepare_proxy(conn)
595
D:\Users\64249\Anaconda3\lib\site-packages\urllib3\connectionpool.py in _prepare_proxy(self, conn)
804 conn.set_tunnel(self._proxy_host, self.port, self.proxy_headers)
--> 805 conn.connect()
806
D:\Users\64249\Anaconda3\lib\site-packages\urllib3\connection.py in connect(self)
343 server_hostname=server_hostname,
--> 344 ssl_context=context)
345
D:\Users\64249\Anaconda3\lib\site-packages\urllib3\util\ssl_.py in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir)
346 if HAS_SNI and server_hostname is not None:
--> 347 return context.wrap_socket(sock, server_hostname=server_hostname)
348
D:\Users\64249\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
461 except OpenSSL.SSL.Error as e:
--> 462 raise ssl.SSLError('bad handshake: %r' % e)
463 break
SSLError: ("bad handshake: SysCallError(-1, 'Unexpected EOF')",)
During handling of the above exception, another exception occurred:
MaxRetryError Traceback (most recent call last)
D:\Users\64249\Anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
448 retries=self.max_retries,
--> 449 timeout=timeout
450 )
D:\Users\64249\Anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
637 retries = retries.increment(method, url, error=e, _pool=self,
--> 638 _stacktrace=sys.exc_info()[2])
639 retries.sleep()
D:\Users\64249\Anaconda3\lib\site-packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
398 if new_retry.is_exhausted():
--> 399 raise MaxRetryError(_pool, url, error or ResponseError(cause))
400
MaxRetryError: HTTPSConnectionPool(host='min-api.cryptocompare.com', port=443): Max retries exceeded with url: /data/v4/all/exchanges?api_key=1bd6b034f5c37235fe86bd57125805ae1164b1f50aea15648073d27a3627b00e&e=Binance (Caused by SSLError(SSLError("bad handshake: SysCallError(-1, 'Unexpected EOF')")))
During handling of the above exception, another exception occurred:
SSLError Traceback (most recent call last)
<ipython-input-11-c02353795ce4> in <module>
12 print(file_name + " is exist jump over")
13 else:
---> 14 get_data(exchange, fsym, tsym, end)
<ipython-input-7-c40a18711b4e> in get_data(exchange, fsym, tsym, end)
25
26 # Call function
---> 27 get_min_histo_data(apiKey, exchange, fsym, tsym, last_file, end)
<ipython-input-6-423ba0f217ce> in get_min_histo_data(apiKey, exchange, fsym, tsym, last_file, end)
18
19 # Request data
---> 20 result_volumn = requests.get(url_vol, params=payload_volumn).json()
21
22 # Get start and end timestamp
D:\Users\64249\Anaconda3\lib\site-packages\requests\api.py in get(url, params, **kwargs)
73
74 kwargs.setdefault('allow_redirects', True)
---> 75 return request('get', url, params=params, **kwargs)
76
77
D:\Users\64249\Anaconda3\lib\site-packages\requests\api.py in request(method, url, **kwargs)
58 # cases, and look like a memory leak in others.
59 with sessions.Session() as session:
---> 60 return session.request(method=method, url=url, **kwargs)
61
62
D:\Users\64249\Anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
531 }
532 send_kwargs.update(settings)
--> 533 resp = self.send(prep, **send_kwargs)
534
535 return resp
D:\Users\64249\Anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
644
645 # Send the request
--> 646 r = adapter.send(request, **kwargs)
647
648 # Total elapsed time of the request (approximately)
D:\Users\64249\Anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
512 if isinstance(e.reason, _SSLError):
513 # This branch is for urllib3 v1.22 and later.
--> 514 raise SSLError(e, request=request)
515
516 raise ConnectionError(e, request=request)
SSLError: HTTPSConnectionPool(host='min-api.cryptocompare.com', port=443): Max retries exceeded with url: /data/v4/all/exchanges?api_key=1bd6b034f5c37235fe86bd57125805ae1164b1f50aea15648073d27a3627b00e&e=Binance (Caused by SSLError(SSLError("bad handshake: SysCallError(-1, 'Unexpected EOF')")))
这是我的代码(相对部分):
url_data = "https://min-api.cryptocompare.com/data/histohour"
payload_data = {
"api_key": apiKey,
"e" : exchange,
"fsym": fsym,
"tsym": tsym,
"limit": limit,
"toTs": start_time
}
result = requests.get(url_data, params=payload_data, verify=False).json()
代码运行良好,可以成功地从该API收集数据80至100次。 但是经过几次获取数据后,发生了该异常:“错误的握手:SysCallError(-1,'意外的EOF')”