Max retries exceeded with url 出现的类似问题:
import time
import requests
headers = {
'Connection': 'close',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36',
}
imgPath='https://p0.ssl.qhimgs1.com/sdr/400__/t0108535573640a7514.jpg'
imgfilepath = 'H:/xiezhen/' + '3.jpg'
print(imgfilepath)
s = requests.session()
s.keep_alive = False
s.proxies = {"https": "80.211.44.98:8080", "http": "80.211.44.98:8080", }
try:
r = requests.get(imgPath, headers=headers)
with open(imgfilepath, 'wb') as f:
f.write(r.content)
except requests.exceptions.ConnectionError as r:
r.status_code="Connection refused"
time.sleep(5)
print('正在保存图片:', imgPath)