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.

 from urllib3 import HTTPConnectionPool

 pool = HTTPConnectionPool('www.baidu.com', maxsize=1)
res = pool.request('GET', '/s', fields={'wd': 'HELLO'})
print(res.status)
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

urllib3 ConnectionPools的更多相关文章

  1. urllib3 PoolManager

    A pool manager is an abstraction for a collection of ConnectionPools.If you need to make requests to ...

  2. python中urllib, urllib2,urllib3, httplib,httplib2, request的区别

    permike原文python中urllib, urllib2,urllib3, httplib,httplib2, request的区别 若只使用python3.X, 下面可以不看了, 记住有个ur ...

  3. urllib3 ProxyManager

    ProxyManager is an HTTP proxy-aware subclass of PoolManager. It produces a singleHTTPConnectionPool ...

  4. A taste of urllib3

    import urllib3 import certifi http = urllib3.PoolManager( cert_reqs='CERT_REQUIRED', # Force certifi ...

  5. python urllib和urllib3包使用

    urllib包 urllib是一个包含几个模块来处理请求的库.分别是: urllib.request 发送http请求 urllib.error 处理请求过程中,出现的异常. urllib.parse ...

  6. Uiautomator--出现报错“urllib3.exceptions.ProtocolError:<'Connection aborted.',error<10054,''>>”的解决方式!

    在运行uiautomator时,出现报错"urllib3.exceptions.ProtocolError:<'Connection aborted.',error<10054, ...

  7. 禁用 urllib3 的安全请求警告

    报错情况: 禁用该警告: import urllib3 urllib3.disable_warnings()

  8. /usr/lib/python2.7/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.2.1) doesn't match a supported version! RequestsDependencyWarning)

    [root@iZwz9bhan5nqzh979qokrkZ ~]# ansible all -m ping /usr/lib/python2.7/site-packages/requests/__in ...

  9. urllib、urllib2、urllib3区别和使用

    python3中把urllib和urllib合并为一个库了,urllib对应urllib.request 1.) python 中最早内置拥有的网络请求模块就是 urllib,我们可以看一下 urll ...

随机推荐

  1. Windbg 线程状态笔记

    1.ntdll!ZwWaitForSingleObject 线程被挂起,如果下面跟着是这样子: RetAddr : Args to Child : Call Site `7766e518 : `fff ...

  2. 关于enum的那些事儿

    自从当年明月的<明朝的那些事儿>爆红之后,以***那些事儿命名的文章便层出不穷.个人认为,这样的命名通俗但具有吸引力,容易接地气.哈哈,所以我也写了几篇以<***那些事儿>的文 ...

  3. Find out who the “mole” is?

    Blueheat Company’s  production server was out of order again. The CEO was very upset and want their ...

  4. shell脚本中的特殊符号

    1.{} 大括号:用法一:通配符扩展eg: ls my_{finger,toe}s这条命令相当于如下命令的组合:ls my_fingers my_toeseg: mkdir {userA,userB, ...

  5. Button的图像位置设置

    [button setImageEdgeInsets:UIEdgeInsetsMake(2, 70, 2,70 )]; [button setImageEdgeInsets:UIEdgeInsetsM ...

  6. ecshop常用语句

    ecshop之中的IF语句: <select name="product_cat" id="product_cat" class="form-c ...

  7. c语言入门教程 / c语言入门经典书籍

    用C语言开始编写代码初级:C语言入门必备(以下两本书任选一本即可) C语言是作为从事实际编程工作的程序员的一种工具而出现的,本阶段的学习最主要的目的就是尽快掌握如何用c语言编写程序的技能.对c语言的数 ...

  8. PopupWindow的简单使用

    测试代码: package com.zzw.testpopuwindows; import android.app.Activity; import android.graphics.Color; i ...

  9. 5)Java部分常用package功能介绍

    1> java.lang    (package)   这个是系统的基础类,比如String等都是这里面的,这个package是唯一一个可以不用import就可以使用的Package 包中关键类 ...

  10. 生日蛋糕 (codevs 1710) 题解

    [问题描述] 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1<=i<=M)层蛋糕是半径为Ri,高度为Hi的圆柱 ...