Skip to content

Commit

Permalink
fix: handled new model response.
Browse files Browse the repository at this point in the history
  • Loading branch information
Almas-Ali committed Jan 30, 2024
1 parent 41e4236 commit 04cc416
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions spyip/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ def trace_me(
headers=headers,
timeout=timeout,
)
data = res.json()
data['as_'] = data.pop('as')

if res.status_code == 200:
return IPResponse(**res.json())
return IPResponse(**data)
else:
raise StatusError(f'Invalid status code: {res.status_code}. Expected 200.')

Expand Down Expand Up @@ -80,8 +83,11 @@ def trace_ip(
headers=headers,
timeout=timeout,
)
data = res.json()
data['as_'] = data.pop('as')

if res.status_code == 200:
return IPResponse(**res.json())
return IPResponse(**data)
else:
raise StatusError(f'Invalid status code: {res.status_code}. Expected 200.')

Expand Down Expand Up @@ -144,8 +150,12 @@ def trace_ip_batch(
timeout=timeout,
json=query_list,
)
response = []
if res.status_code == 200:
return [IPResponse(**x) for x in res.json()]
for x in res.json():
x['as_'] = x.pop('as')
response.append(IPResponse(**x))
return response
else:
raise StatusError(f'Invalid status code: {res.status_code}. Expected 200.')
# 408 Request Timeout
Expand Down

0 comments on commit 04cc416

Please sign in to comment.