Two tiny changes (#27)
* Use .ok property instead of status-code check against 200 * Tighter try/except handling\nPutting less code into the try block
This commit is contained in:
parent
e1f6c0af2f
commit
36b6f603b4
16
pwned.py
16
pwned.py
@ -29,7 +29,7 @@ def lookup_pwned_api(pwd):
|
||||
head, tail = sha1pwd[:5], sha1pwd[5:]
|
||||
url = 'https://api.pwnedpasswords.com/range/' + head
|
||||
res = requests.get(url)
|
||||
if res.status_code != 200:
|
||||
if not res.ok:
|
||||
raise RuntimeError('Error fetching "{}": {}'.format(
|
||||
url, res.status_code))
|
||||
hashes = (line.split(':') for line in res.text.splitlines())
|
||||
@ -43,18 +43,18 @@ def main(args):
|
||||
pwd = pwd.strip()
|
||||
try:
|
||||
sha1pwd, count = lookup_pwned_api(pwd)
|
||||
|
||||
if count:
|
||||
foundmsg = "{0} was found with {1} occurrences (hash: {2})"
|
||||
print(foundmsg.format(pwd, count, sha1pwd))
|
||||
ec = 1
|
||||
else:
|
||||
print("{} was not found".format(pwd))
|
||||
except UnicodeError:
|
||||
errormsg = sys.exc_info()[1]
|
||||
print("{0} could not be checked: {1}".format(pwd, errormsg))
|
||||
ec = 1
|
||||
continue
|
||||
|
||||
if count:
|
||||
foundmsg = "{0} was found with {1} occurrences (hash: {2})"
|
||||
print(foundmsg.format(pwd, count, sha1pwd))
|
||||
ec = 1
|
||||
else:
|
||||
print("{} was not found".format(pwd))
|
||||
return ec
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user