Handle non-200 status codes explicitly
This commit is contained in:
parent
6955575a64
commit
f252886b95
11
pwned.py
11
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)
|
||||||
hashes = (s.split(':') for s in r.text.split('\r\n'))
|
if res.status_code != 200:
|
||||||
pred = ((head + t,count) for t,count in hashes if t == tail)
|
raise RuntimeError('Error fetching "{}": {}'.format(
|
||||||
|
url, res.status_code))
|
||||||
|
|
||||||
|
hashes = (s.split(':') for s in r.text.split('\r\n'))
|
||||||
|
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