Max retries exceeded with url错误

进行requests库学习的时候,报Max retries exceeded with url错误,网上查询说是,用下面这个解决方法没用,后来关闭了fiddler后发现就可以了,可能fiddler开的连接数太多了

http连接太多没有关闭导致的

解决办法:

1、增加重试连接次数

  requests.adapters.DEFAULT_RETRIES = 5
  • 1

2、关闭多余的连接

requests使用了urllib3库,默认的http connection是keep-alive的,requests设置False关闭。

操作方法

s = requests.session()
  s.keep_alive = False
import requests,json,unittest
def send_req(url,method,data=None):
if method=='GET':
requests.adapters.DEFAULT_RETRIES = 5
s = requests.session()
s.keep_alive = False
res=requests.get(url=url).json()
return json.dumps(res,indent=2)
else:
res=requests.post(url=url,data=data)
return res.json()
url=r'https://www.baidu.com/home/xman/data/tipspluslist?indextype=manht&_req_seqid=0xe84d39f7000079b2&asyn=1&t=1535105478702&sid=26524_1442_21097_26921_22159'
res=send_req(url,'GET')

转载于:https://www.cnblogs.com/classid/p/9532790.html

你可能感兴趣的:(Max retries exceeded with url错误)