Python SSL Problem with PIP, Requests and Other - python

I've got a problem with a SSLError that appeared since last week.
I've used Python on my machine for a few years without any problem, but now whenever i try to use a library that connects to the web, a SSLError is thrown.
I've tried other solutions to make PIP and Requests work while avoiding the certificate check, but now i need to make it work to use an Azure library.
I know it's not a problem of the Wifi connection i'm using because it works fine on other machines. Could it be something i've installed on the machine? Maybe a VPN? Is there a way to check what is "blocking" the connection?
This is an example of the error when using the Azure Iot Hub library:
ClientRequestError: Error occurred in request., SSLError: HTTPSConnectionPool(host='iothubstreamdemo.azure-devices.net', port=443): Max retries exceeded with url: /devices?api-version=2020-03-01 (Caused by SSLError(SSLError(0, 'unknown error (_ssl.c:3622)'),))
And this is while using requests:
SSLError: HTTPSConnectionPool(host='example.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(0, 'unknown error (_ssl.c:3622)'),))
Thanks in advance.

Related

How to run a Python 3 script in OWASP ZAP?

I'm using ZAP to run a scan of a website from the command line, using the form-based authentication script found in the ZAP API Documentation.
java -jar ./zap-2.11.1.jar -script ./auth_script.py
However, it looks like ZAP uses Jython 2.7 instead of Python 3, so running the script this way doesn't work.
I've also tried running the script directly (i.e. python3 auth_script.py), but it throws the following error:
requests.exceptions.ProxyError: HTTPConnectionPool(host='127.0.0.1', port=8080): Max retries exceeded with url: http://zap/JSON/context/action/includeInContext/?contextName=context&regex=https%3A%2F%2Fwebsite.com%2F&apikey=9qFbZD4udTzFVYo0u5UzkZX9iuzbdcJDRAquTfRk
(Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))
Has anyone used this form-based authentication script before? How did you get it to work?

After Internet Outage, Python can't request API endpoints properly

Basically there was an internet outage yesterday, and I tried to run my FastAPI python backend which calls API endpoints, I was getting this error during the outage and wasn't surprised since I had no internet.
However, now that i've got internet back, the API's are still not requesting properly ( Other developers i'm working with who didn't face this outage have no problems)
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='www.api.com', port=443): Max retries exceeded with url: /filter/professor/?&page=5&filter=teacherlastname_sort_s+asc&query=*%3A*&queryoption=TEACHER&queryBy=schoolId&sid=4714 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x00000184D99C0D00>, 'Connection to www.api.com timed out. (connect timeout=5)'))
What I tried:
Re-installed all pip requirements
Re-installing the repo ( New virtual environment)
I was trying to look online, and people say some config files might have corrupted, still unsure abt this

SSL error only in python command window with apify request

I am trying to use endpoint from apify.com. When I run my request in web browser with token everything is fine but if I run my request via requests library from python console I am getting following error:
SSLError: HTTPSConnectionPool(host='', port=443): Max retries exceeded with url: /endpoint?token=token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1131)')))
Moreover if I set verify = False in my request than request is working. Does anyone have an idea what can be wrong? Thanks in advance
I had this issue come up a few weeks ago.
>>> pip install certifi
>>> python -m certifi
I'm not certain that one needs to actually call the module to get it's functionality, but I did and it solved the error. More info on Certifi here. It is also a recommended package extension to requests from their website. I added those lasts bits because I was wary of installing a package that ostensibly was never called after installation.
Solution was to install internal company SSL package for managing SSL connection from python. There was a recent change.

What exactly causes the "unable to get local issuer certificate" error when accessing an otherwise accessible (via browser) website URL?

I'm on macOS Monterey 12.3 running Python 3.9.7 installed via brew. Given this minimal replication of my production code:
import requests
try:
response = requests.get(website)
except requests.exceptions.SSLError as e:
print("Error: " + str(e))
... it spits out this error:
Error: HTTPSConnectionPool(host='<SNIP>', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))
Unfortunately, the website URL is something that I cannot share. But it's definitely accessible via HTTPS on Chrome. I'm aware of workarounds and have successfully fixed it by following this one, but I have deployed the same identical code on a Linux server and it errors out all the same (so I'm assuming this isn't a MacOS specific issue). Is this a misconfiguration of the SSL cert on the server? And if so, how is it fixed?

Getting error while web scraping using python requests module

Trying to grab the content of website using python 3.6.2.Getting below error.
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.amazon.in', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied
(_ssl.c:748)'),))
Code:
import requests
from bs4 import BeautifulSoup
r=requests.get("https://www.amazon.in/")
r.content
Help me in fixing this!
try http instead of https. It worked for me
You can check your connection and ability to communicate with TLS protocol by typing following command:
openssl s_client -connect www.amazon.in:443
Anyway, your python code is correct and works for me.

Categories