当前位置: 首页>>代码示例>>Python>>正文


Python PoolManager.urlopen方法代码示例

本文整理汇总了Python中urllib3.poolmanager.PoolManager.urlopen方法的典型用法代码示例。如果您正苦于以下问题:Python PoolManager.urlopen方法的具体用法?Python PoolManager.urlopen怎么用?Python PoolManager.urlopen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib3.poolmanager.PoolManager的用法示例。


在下文中一共展示了PoolManager.urlopen方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ConnectionPool

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import urlopen [as 别名]
class ConnectionPool(object):

    NUM_POOLS = 5    # one pool per host, usually just 1 pool is needed
                      # when redirect happens, one additional pool will be created

    def __init__(self, host, path, timeout=0, maxsize=50):
        self.host = host
        self.path = path
       
        self.pool = PoolManager(
            self.NUM_POOLS,
            headers=None,
            cert_reqs='CERT_REQUIRED', # Force certificate check
            ca_certs=certifi.where(),  # Path to the Certifi bundle
            strict=True,         # TODO more comments to explain these parameters
            timeout=timeout,
            maxsize=maxsize,
            block=True,
        )

    def send_receive(self, url, request_headers, request_body):

        global _network_io_time

        if _NETWORK_IO_TIME_COUNT_FLAG:
            begin = time.time()

        response = self.pool.urlopen(
            'POST', self.host + self.path + url, 
            body=request_body, headers=request_headers,
            redirect=False,
            assert_same_host=False,
        )

        if _NETWORK_IO_TIME_COUNT_FLAG:
            end = time.time()
            _network_io_time += end - begin

        # TODO error handling
        response_headers = dict(response.getheaders())
        response_body = response.data # TODO figure out why response.read() don't work

        return response.status, response.reason, response_headers, response_body
开发者ID:aliyun,项目名称:aliyun-tablestore-python-sdk,代码行数:45,代码来源:connection.py


注:本文中的urllib3.poolmanager.PoolManager.urlopen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。