diff options
author | Linus Nordberg <linus@nordu.net> | 2017-10-26 16:52:01 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2017-10-26 16:52:01 +0200 |
commit | 4525c721aa20873ea90fc6ea1a1dd5a376f172df (patch) | |
tree | 2b5dfa09a91be324cd66cc7a1fab4e23f6d39fea | |
parent | 9349ea5d490dac5d45040d859944a58111d8d632 (diff) |
Retry submission when server replies with 429 Too Many Requests.
Patch by Magnus Ahltorp from map/submission-fix.
-rw-r--r-- | tools/certtools.py | 44 |
1 files 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 |