使用服务测试程序多次连续访问线上服务时报如上图错误,提示Max retries exceeded ,解决办法:
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
session = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
url='https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1991157763,2687006238&fm=26&gp=0.jpg'
rtn = session.get(url)
#rtn = requests.get(url)
print ('tm: {}'.format(rtn.elapsed.total_seconds()))