From 4525c721aa20873ea90fc6ea1a1dd5a376f172df Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Thu, 26 Oct 2017 16:52:01 +0200 Subject: Retry submission when server replies with 429 Too Many Requests. Patch by Magnus Ahltorp from map/submission-fix. --- tools/certtools.py | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/tools/certtools.py b/tools/certtools.py index 84d0bd9..485a8ac 100644 --- a/tools/certtools.py +++ b/tools/certtools.py @@ -180,14 +180,18 @@ def unpack_tls_array(packed_data, length_len): def add_chain(baseurl, submission, session=None): try: - result = urlpost(baseurl + "ct/v1/add-chain", json.dumps(submission), session=session) - if result.status_code == requests.codes.ok: - return result.json() - else: - print "ERROR:", result.status_code, result.text - if result.status_code == 400: - return None - sys.exit(1) + while True: + result = urlpost(baseurl + "ct/v1/add-chain", json.dumps(submission), session=session) + if result.status_code == requests.codes.ok: + return result.json() + else: + print "ERROR:", result.status_code, result.text + if result.status_code == 400: + return None + if result.status_code == 429: + sleep(1) + continue + sys.exit(1) except ValueError, e: print "==== FAILED REQUEST ====" print submission @@ -198,16 +202,20 @@ def add_chain(baseurl, submission, session=None): def add_prechain(baseurl, submission, session=None): try: - result = urlpost(baseurl + "ct/v1/add-pre-chain", - json.dumps(submission), session=session) - - if result.status_code == requests.codes.ok: - return result.json() - else: - print "ERROR:", result.status_code, result.text - if result.status_code == 400: - return None - sys.exit(1) + while True: + result = urlpost(baseurl + "ct/v1/add-pre-chain", + json.dumps(submission), session=session) + + if result.status_code == requests.codes.ok: + return result.json() + else: + print "ERROR:", result.status_code, result.text + if result.status_code == 400: + return None + if result.status_code == 429: + sleep(1) + continue + sys.exit(1) except ValueError, e: print "==== FAILED REQUEST ====" print submission -- cgit v1.1