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.