generated from Hazel/python-project
retries if connection fails
This commit is contained in:
parent
ae997fd0bf
commit
ec24193a72
@ -9,7 +9,7 @@ def main():
|
||||
c = Connection(cache_enable=False, request_delay=1.5, rate_limit_status_codes={200})
|
||||
c.generate_headers()
|
||||
|
||||
print(c.get("http://ip.org/"))
|
||||
print(c.get("http://www.does_not_exist.xyz"))
|
||||
|
||||
|
||||
def cli():
|
||||
|
@ -117,10 +117,15 @@ class Connection:
|
||||
if to_wait > 0:
|
||||
log.info(f"waiting {to_wait} at attempt {attempt}: {url}")
|
||||
time.sleep(to_wait)
|
||||
|
||||
response = self.session.send(request.prepare())
|
||||
|
||||
self.last_request = time.time()
|
||||
|
||||
try:
|
||||
response = self.session.send(request.prepare())
|
||||
except requests.ConnectionError:
|
||||
if self.max_retries is not None and self.max_retries <= attempt:
|
||||
raise
|
||||
return self.send_request(request, attempt=attempt+1)
|
||||
|
||||
if not self.validate_response(response):
|
||||
if self.max_retries is not None and self.max_retries <= attempt:
|
||||
|
Loading…
x
Reference in New Issue
Block a user