程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[bug] Python requests initiates a request and reports Max retries exceeded with URL

編輯:Python

On the local machine , Call one repeatedly with high frequency API Interface , appear “Max retries exceeded with url”, The connection is rejected .

Let's talk about , Meet this bug The process of :

In the server developed a recognition image text API Interface , Also deployed , Prepare to test the interface ,

The landlord is ready to check the 2000 Test with multiple pictures , That is to say, it needs to be called repeatedly API Interface 2000 many times .

Request interface 50 Many times , The interface will not feed back information , Report errors , Connection error , Unable to connect , At first, I thought it was a network problem , Then start calling again until it is adjusted 300 many times , Report errors , Connection error , Unable to connect , It's been like this for about seven or eight times ...

So it turns on “ use Baidu Search ”, Many tutorials are also available online , for example :

  • In the use of requests Visit the same one many times ip when , Especially in high-frequency visits ,http Too many connections are not closed Max retries exceeded with url Error of
res = requests.post(url, headers=headers, json=parm, cookies=cookies)
# After the request is completed , Close the connection ( If for the same request When initiated with high frequency , There may be Max retries exceeded with url)
res.close()
# It was observed that , Close after use res.close(), Can solve Max retries exceeded with url Error of 

https://www.cnblogs.com/cuitang/p/15407448.html

  • http Too many connections are not closed

terms of settlement :

s=requests.session()
s.keep_alive=False
s.post(url)

https://laidefa.blog.csdn.net/article/details/102740747

# Increase the number of reconnections :
requests.DEFAULT_RETRIES = 5
s=requests.session()
# Turn off redundant connections 
s.keep_alive=False

https://blog.csdn.net/llllllkkkkkooooo/article/details/107637980

  • headers Add fields to it Connection, The value is close
headers = {
'Connection':'close'}

https://www.jianshu.com/p/afe366963379

The owners of the above schemes have tried , Didn't solve my problem ...【 The main thing is the wrong medicine , There is something wrong with the medicine , ha-ha 】

However, the landlord did not give up solving the problem , Keep looking for information !

Finally found a suitable “ drug ”, Share below :

That is to say , Just install this package :pip install pyopenssl or pip install -U pyopenssl

https://www.jianshu.com/p/5a57ad129e4b


The above content is only for personal record reference , Non standard answers

https://blog.csdn.net/weixin_45520735/article/details/115260374


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved