0

so i have this weird problem:

i'm making myself familiar with the Rest-API from https://haveibeenpwned.com/API/v2.

I wrote a small Python script to check for hashes. When I run it in the Anaconda prompt it just works fine. Entering the query in the browser works too. But when i try it in PowerShell, it suddenly crashes ...but the exception raised doesn't make any sense to me - at least in this particular context. There might actually be an issue if I called the query multiple times as described here. But in my case its only called once.

So this is the code:

import requests
import sys

print("Checking haveibeenpwnd.com for hash: \'", sys.argv[1], "\'")

query = 'https://api.pwnedpasswords.com/range/' + sys.argv[1]

print("DEBUG : URL is: ", query)

try:
    req = requests.get (query)
    print(req.text)
except Exception as e:
    print("EXCEPTION : Something went wrong...\n")
    print(str(e) + "\n")

The Conda prompt works as intended:

d:\dev\PasswordChecker>python PasswordChecker.py FACD3
Checking haveibeenpwnd.com for password: ' FACD3 '
DEBUG : URL is:  https://api.pwnedpasswords.com/range/FACD3
00286E9BB9584421CD4BE0E04C6FBC1B9A4:1
01D3C8B75DD8386F5465924A71BC27050E7:1
...

But PowerShell crashes:

PS D:\dev\PasswordChecker> python .\PasswordChecker.py
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 588, in urlopen
    conn = self._get_conn(timeout=pool_timeout)
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 248, in _get_conn
    return conn or self._new_conn()
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 816, in _new_conn
    raise SSLError("Can't connect to HTTPS URL because the SSL "
urllib3.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\util\retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.pwnedpasswords.com', port=443): Max retries exceeded with url: /range/FAFA3 (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".\PasswordChecker.py", line 8, in <module>
    req = requests.get ('https://api.pwnedpasswords.com/range/FAFA3')
  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.pwnedpasswords.com', port=443): Max retries exceeded with url: /range/FAFA3 (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))
PS D:\dev\PasswordChecker> python .\PasswordChecker.py FAFC3
Checking haveibeenpwnd.com for password: ' FAFC3 '
DEBUG : URL is:  https://api.pwnedpasswords.com/range/FAFC3
EXCEPTION : Something went wrong...

HTTPSConnectionPool(host='api.pwnedpasswords.com', port=443): Max retries exceeded with url: /range/FAFC3 (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))

I don't mind using Conda but it would be fairly interesting to know if there are some issues with Python and PowerShell in general, which can manifest in strange ways.

Thanks for your support, SH

EDIT: probably its important to mention - probably not: It's a Win10 machine. I'm using VS2019 to code. Python is 3.7.

1 Answer 1

0

The version of the requests library you have installed on powershell might be different from the one running in conda, which could explain why you get different results.

It looks like powershell is missing the SSL library. You may need to have that installed. I was under the impression that it was bundled with the requests library, so a reinstall of requests might work for you: pip install requests --upgrade.

If you just want to get rid of the error, and you don't care about verifying SSL certificates, you may want to just pass verify=False as a parameter with your get request:

requests.get(query, verify=False)

More information about this can be found here: http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification

1
  • 1
    Thanks! This was the issue. However I couldn't just fix it via pip install requests --upgrade bc this also needs the SSL socket and creates the same problem. Installing the latest OpenSSL library via the installer fixed it though.
    – Codebaard
    Commented Apr 20, 2019 at 12:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .