我一直使用请求模块中的.get命令得到此错误。
HTTPSConnectionPool(host='google.com', port=443):
Max retries exceeded with url:
/ (Caused by SSLError(
SSLError("bad handshake: Error([('SSL routines',
'ssl_cipher_list_to_bytes', 'no ciphers available')],)",),))
这是我的代码
import ssl
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import
PoolManager
from requests.packages.urllib3.util import ssl_
CIPHERS = ( 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-
ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AElS256-
SHA384: ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-
AES128-GCM-SHA256:ECDHE-RSA-AES128-
SHA256:AES256-SHA' )
class TlsAdapter(HTTPAdapter):
def __init__(self, ssl_options=0, **kwargs):
self.ssl_options = ssl_options
super(TlsAdapter, self).__init__(**kwargs)
def init_poolmanager(self, *pool_args, **pool_kwargs):
ctx = ssl_.create_urllib3_context(ciphers=CIPHERS,
cert_reqs=ssl.CERT_REQUIRED,
options=self.ssl_options)
self.poolmanager = PoolManager(*pool_args,
ssl_context=ctx, **pool_kwargs)
s = requests.session()
adapter = TlsAdapter()
s.mount("https://", adapter)
try:
r = s.get('https://google.com')
print(r)
except Exception as e:
print(e)
有人知道这是怎么回事吗?我以为这样可以。