jenkinsapi出现HTTPConnectionPool Max retires exceeded异常

python项目通过使用jenkinsapi远程控制jenkins

jenkinsapi使用的远程连接方法是requests包,requests包又使用了urllib3,urllib3又引用了httplib。

"""
urllib3 - Thread-safe connection pooling and re-using.
"""

requests使用连接池机制,连接池

http的通过设置

Connection:keep-alive

的header头来表明是长连接,通过传输层tcp的长连接实现

短连接会占用较多的端口

socket就是源IP、源端口、协议(scheme)、目的IP、目的端口的五元组

 

import requests
sess = requests.Session()
adapter = requests.adapters.HTTPAdapter(pool_connections=100, pool_maxsize=100)
sess.mount('http://', adapter)
resp = sess.get("/mypage")


requests常见的一些错误提示有:
  • Failed to establish a new connection:
  • Connection pool is full, discarding connection
 
 

The newest version of Requests does in fact keep the TCP connection alive after your request.. If you do want your TCP connections to close, you can just configure the requests to not use keep-alive.

s = requests.session()
s.config['keep_alive'] = False

s.keep_alive = False


requests的默认连接池是10个,每个连接池的最大连接数默认也是10个

 

https://segmentfault.com/q/1010000000517234

https://www.kawabangga.com/posts/2740

http://blog.oldboyedu.com/tcp-wait/

http://blog.csdn.net/hetaohappy/article/details/51851880

http://www.cnblogs.com/0201zcr/p/4694945.html

http://codewenda.com/%E6%88%91%E5%8F%AF%E4%BB%A5%E6%9B%B4%E6%94%B9python%E7%9A%84%E8%AF%B7%E6%B1%82%E6%A8%A1%E5%9D%97%E7%9A%84%E8%BF%9E%E6%8E%A5%E6%B1%A0%E5%A4%A7%E5%B0%8F%E5%90%97%EF%BC%9F/

http://docs.python-requests.org/zh_CN/latest/user/advanced.html

https://www.villainhr.com/page/2016/07/23/python%E4%B8%AD%E7%9A%84requests

https://www.villainhr.com/page/2016/07/23/python%E4%B8%AD%E7%9A%84requests

http://blog.csdn.net/hzrandd/article/details/74463313

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值