requests中自定义adapter
Posted tnyleyon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了requests中自定义adapter相关的知识,希望对你有一定的参考价值。
# encoding:utf-8
import ssl
from requests import sessions
from requests import Request
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
class Ssl3HttpAdapter(HTTPAdapter):
def __int__(self):
super(HTTPAdapter, self).__init__()
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(
num_pools=connections,
maxsize=maxsize,
block=block,
strict=True,
ssl_version=ssl.PROTOCOL_SSLv3
)
adapter = Ssl3HttpAdapter()
s = sessions.Session()
s.mount("http://172",adapter=adapter)
r = Request(‘GET‘, ‘http://172.21.2.3:8009/ad09‘)
p = r.prepare()
# resp=s.request(‘GET‘, ‘http://172.21.2.3:8009/ad09‘)
resp = s.send(p)
print resp.status_code
以上是关于requests中自定义adapter的主要内容,如果未能解决你的问题,请参考以下文章