diff --git a/pwned.py b/pwned.py index 716b931..cfcf961 100644 --- a/pwned.py +++ b/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