4
我試圖用python Request包登錄和刮取航空公司網站。我正在嘗試加載主網站時遇到了下面的錯誤。該代碼在去年使用,但直到現在我還沒有嘗試使用新的請求2.2.1。任何想法是怎麼回事?Python請求:[SSL:CERTIFICATE_VERIFY_FAILED]證書驗證失敗(_ssl.c:547)
[SSL:CERTIFICATE_VERIFY_FAILED]證書驗證失敗(_ssl.c:547)
我使用的要求2.2.1。
ssladapter.py
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
from ssl import PROTOCOL_TLSv1
class SSLAdapter(HTTPAdapter):
'''An HTTPS Transport Adapter that uses an arbitrary SSL version.'''
__attrs__ = ['max_retries', 'config', '_pool_connections', '_pool_maxsize', '_pool_block', 'ssl_version']
def __init__(self, ssl_version=None, **kwargs):
self.ssl_version = ssl_version
super(SSLAdapter, self).__init__(**kwargs)
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connections,
maxsize=maxsize, block = block,
ssl_version=self.ssl_version)
scrape.py
import requests
import ssladapter
from ssl import PROTOCOL_TLSv1
session = requests.Session()
session.mount('https://', ssladapter.SSLAdapter(ssl_version=PROTOCOL_TLSv1))
request = session.get("www.delta.com")
!此處提出SSLERROR。