Handle non-200 status codes explicitly
This commit is contained in:
parent
6955575a64
commit
f252886b95
9
pwned.py
9
pwned.py
@ -8,11 +8,14 @@ def lookup_pwned_api(pwd):
|
|||||||
head = sha1pwd[:5]
|
head = sha1pwd[:5]
|
||||||
tail = sha1pwd[5:]
|
tail = sha1pwd[5:]
|
||||||
|
|
||||||
r = requests.get('https://api.pwnedpasswords.com/range/{0}'.format(head))
|
url = 'https://api.pwnedpasswords.com/range/' + head
|
||||||
if r.status_code == 200:
|
res = requests.get(url)
|
||||||
|
if res.status_code != 200:
|
||||||
|
raise RuntimeError('Error fetching "{}": {}'.format(
|
||||||
|
url, res.status_code))
|
||||||
|
|
||||||
hashes = (s.split(':') for s in r.text.split('\r\n'))
|
hashes = (s.split(':') for s in r.text.split('\r\n'))
|
||||||
pred = ((head + t,count) for t,count in hashes if t == tail)
|
pred = ((head + t,count) for t,count in hashes if t == tail)
|
||||||
|
|
||||||
password_hit = next(pred, None)
|
password_hit = next(pred, None)
|
||||||
return password_hit
|
return password_hit
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user