diff options
author | Magnus Ahltorp <map@kth.se> | 2017-04-07 15:41:15 +0200 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2017-04-07 15:41:15 +0200 |
commit | 4ddc3838c0039fbf009600b611257d8506c9824f (patch) | |
tree | 49fc7befebd84a05ff9a9589331ec5c38d07f926 /tools/certtools.py | |
parent | 8fb19e1dd19998b7e5b2cff9031eaf52dac46b51 (diff) |
Submit certificates on the same http session.submission-fix
Retry submission when server replies with 429 Too Many Requests.
Diffstat (limited to 'tools/certtools.py')
-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 |