zoukankan      html  css  js  c++  java
  • urllib3 ConnectionPools

    A connection pool is a container for a collection of connections to a specific host.
    If you need to make requests to the same host repeatedly, then you should use a HTTPConnectionPool.

    1 from urllib3 import HTTPConnectionPool
    2 
    3 
    4 pool = HTTPConnectionPool('www.baidu.com', maxsize=1)
    5 res = pool.request('GET', '/s', fields={'wd': 'HELLO'})
    6 print(res.status)
    7 print(res.data)

    By default, the pool will cache just one connection. If you’re planning on using such a pool in a multithreaded
    environment, you should set the maxsize of the pool to a higher number, such as the number of threads. You can
    also control many other variables like timeout, blocking, and default headers.

    A ConnectionPool can be used as a context manager to automatically clear the pool after usage.

    with HTTPConnectionPool('www.baidu.com', maxsize=1) as pool:
        res = pool.request('GET', '/s', fields={'wd': 'HELLO'})
        print(pool.pool)

    API

  • 相关阅读:
    第七周课程总结&实验报告(五)
    2020软件工程作业02
    自我介绍
    2019学期总结
    2019 第二次实验报告
    git 小错误
    12
    2019第十一周作业
    第十周作业
    第九周
  • 原文地址:https://www.cnblogs.com/shadowwalker/p/5283074.html
Copyright © 2011-2022 走看看