SSL指紋驗(yàn)證
class CipherAdapter(HTTPAdapter):
"""發(fā)起HTTP請求時(shí)進(jìn)行SSL指紋驗(yàn)證,以增強(qiáng)安全性,解決一些403問題"""
def init_poolmanager(self, *args, **kwargs):
context = create_urllib3_context(ciphers='DEFAULT:@SECLEVEL=2')
kwargs['ssl_context'] = context
return super(CipherAdapter, self).init_poolmanager(*args, **kwargs)
def proxy_manager_for(self, *args, **kwargs):
context = create_urllib3_context(ciphers='DEFAULT:@SECLEVEL=2')
kwargs['ssl_context'] = context
return super(CipherAdapter, self).proxy_manager_for(*args, **kwargs)
# 使用SSL指紋驗(yàn)證
sess.mount('https://www.douyin.com', CipherAdapter())
#requests ssl指紋驗(yàn)證#
標(biāo)簽: