retry重试
作者:互联网
import requests
from retrying import retry
PROXY_POOL_URL = 'http://127.0.0.1:5555/random'
def get_proxxy():
response = requests.get(PROXY_POOL_URL)
if response.status_code == 200:
return response.text
else:
return None
@retry(stop_max_attempt_number=5, retry_on_result=lambda x: x is None)
def run():
try:
proxy = get_proxxy()
print(proxy)
proxies = {
'http': 'http://' + proxy,
'https': 'https://' + proxy
}
response = requests.get('http://www.httpbin.org/get', proxies=proxies)
if response.status_code == 200:
return response.text
except Exception as e:
print('Error', e.args)
return None
run()
标签:retry,http,get,重试,proxy,return,response 来源: https://www.cnblogs.com/wangshx666/p/16099795.html