python类CONNECTTIMEOUT_MS的实例源码

httpadapter.py 文件源码 项目:searx-stats2 作者: dalf 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def set_timeout(self, timeout):
        self.timeout = int(timeout)
        self.curl_handler.setopt(pycurl.CONNECTTIMEOUT_MS, self.timeout)
        self.curl_handler.setopt(pycurl.TIMEOUT_MS, self.timeout)
httpadapter.py 文件源码 项目:searx-stats2 作者: dalf 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self,
                 url,
                 curl_handler,
                 method='GET',
                 headers=None,
                 cookies=None,
                 callback=None,
                 callback_parameters=None,
                 data=None,
                 timeout=5000,
                 ssl_verification=True,
                 proxy=None
                 ):

        if headers is None:
            headers = {}

        if cookies is None:
            cookies = {}

        if callback is None:
            callback = callback_get_response

        if callback_parameters is None:
            callback_parameters = ()

        self.url = url
        self.timeout = timeout

        self.callback = callback
        self.callback_parameters = callback_parameters
        self.curl_handler = curl_handler
        self._response_buffer = BytesIO()
        self.response = None

        # curl_handler
        curl_handler.setopt(curl_handler.URL, url)

        curl_handler.setopt(curl_handler.WRITEFUNCTION, self._response_buffer.write)

        curl_handler.setopt(curl_handler.SSL_VERIFYPEER, int(ssl_verification))

        curl_handler.setopt(curl_handler.CONNECTTIMEOUT_MS, self.timeout)
        curl_handler.setopt(curl_handler.TIMEOUT_MS, self.timeout)

        curl_handler.setopt(curl_handler.HTTPHEADER,
                            ['{0}: {1}'.format(k, v)
                             for k, v in headers.items()])

        if data is not None:
            curl_handler.setopt(curl_handler.POSTFIELDS, urlencode(data))

        if proxy is not None:
            curl_handler.setopt(curl_handler.PROXY, proxy)

        if cookies:
            curl_handler.setopt(curl_handler.COOKIE, '; '.join('{0}={1}'.format(k, v)
                                for k, v in cookies.items()))
        else:
            curl_handler.unsetopt(curl_handler.COOKIE)


问题


面经


文章

微信
公众号

扫码关注公众号