Skip to content

Commit

Permalink
skip over chunks that result in 400 client error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Mar 22, 2024
1 parent 8d9739c commit ccd6a11
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions scripts/local_assignment_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,13 @@ def request_assignments(subscription_plan_uuid, chunk_id, emails_for_chunk, envi
response.raise_for_status()
except requests.exceptions.HTTPError:
# if it's a 401, try refetching the JWT and re-try the request
print(response.content)
if response.status_code == 401:
print('EXPIRED JWT, REFETCHING...')
response = _post_assignments(subscription_plan_uuid, emails_for_chunk, environment, fetch_jwt)
response.raise_for_status()
else:
raise
print('Continuing past this exception.')

response_data = response.json()

Expand Down Expand Up @@ -288,9 +289,14 @@ def do_assignment_for_chunk(

results_for_chunk = []
if payload_for_chunk:
results_for_chunk = request_assignments(
subscription_plan_uuid, chunk_id, payload_for_chunk, environment, fetch_jwt,
)
try:
results_for_chunk = request_assignments(
subscription_plan_uuid, chunk_id, payload_for_chunk, environment, fetch_jwt,
)
except Exception as exc:
print(exc)
print('continuing on...')
return
with open(results_file, 'a+') as f_out:
writer = csv.writer(f_out, delimiter=',')
writer.writerows(results_for_chunk)
Expand Down

0 comments on commit ccd6a11

Please sign in to comment.