Requests certificate error in jupyter notebook / jupyter lab - python - python

When running:
import requests
requests.get("https://github.com")
I get the following error:
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)')))
If however i run the same command in iPython the command runs with no error.
I also checked the path to the certificate for both the notebook and iPython with:
requests.certs.where()
And the path is the same for both.
I would really appreciate any help!

Related

Poetry cannot handle sources which redirect after setting cert

I have a pypi server, TLS server cert signed by self signed CA.
I added it as a source (default, secondary = false) to my toml file using
poetry source add mypypiserver https://server.url/
I added the CA cert using
poetry config certificates.mypypiserver.cert /path/to/ca.crt
When attempting to add external packages from pypi, such as matplotlib, even if I specify the source as pypi, I get an SSLError.
poetry add --source pypi matplotlib
Verbose logging tells me it tries to access /python-dateutil/ which results in a 303 redirect to https://pypi.org/simple/python-dateutil/.
Errors:
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)
HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/python-dateutil/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
I suspect this is because the certificate of pypi.org does not match the self signed CA certificate.
How can this be resolved?

How do I fix a SSL Certificate error when using a get()?

I am running a requests line like the following:
reqs = requests.get('http://test.com')
I am being returned the following error:
SSLError: HTTPSConnectionPool(host='test.com', port=443): Max retries exceeded with url: /?q=test.org (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
I have tried the following:
pip install python-certifi-win32
pip install --upgrade certifi
And neither seem to work. Does anyone know how to fix this?
Ahh, recreating here as the syntax in the comments is always hard to read.
I've found for the requests library, when testing on the local machine I need to put this at top of file:
import os # Obviously!
os.environ['NO_PROXY'] = '127.0.0.1'

SSL Error (Port=443) Max retries exceeded when trying to import osmnx data in Jupiter Notebook

When trying to run this line
G = ox.graph_from_place('Piedmont, CA, USA', network_type='drive')
I get this error:
SSLError: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?format=json&polygon_geojson=1&dedupe=0&limit=50&q=Piedmont%2C+CA%2C+USA (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
I googled and found this could be a solution but I got the same error message:
from geopy.geocoders import Nominatim
geopy.geocoders.options.default_user_agent = 'my_app/1'
geopy.geocoders.options.default_timeout = 7
geolocator = Nominatim()
print(geolocator.headers)
{'User-Agent': 'my_app/1'}
print(geolocator.timeout)
(I changed my/app_1 to "ABC" in the code above)
I also tried - since that was in another solution on stackoverflow, this:
pip install certifi
but the same SSL-error appeared.
I'm using Anaconda Navigator 2.1.1 on Mac (OS Big Sur) and Jupiter Notebook 6.3.0
Can someone tell me what I'm doing wrong please? I'm behind a company proxy and assume that's the issue.
Does this URL work in your browser:
https://nominatim.openstreetmap.org//search?format=json&polygon_geojson=1&dedupe=0&limit=50&q=Piedmont%2C+CA%2C+USA
you can also set request params:
ox.config(request_kwargs={})

SSL: CERTIFICATE_VERIFY_FAILED certificate verify failed - Google Colab

I am trying to scrape data from a url using beautifulsoup. Below is my code
import requests
URL = "https://bigdataldn.com/speakers/"
page = requests.get(URL)
print(page.text)
However I am getting the following error when I run the code in google colab.
SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)
During handling of the above exception, another exception occurred:
MaxRetryError Traceback (most recent call last)
MaxRetryError: HTTPSConnectionPool(host='bigdataldn.com', 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:1091)')))
The above code works fine for other urls.
Can someone help me figure out how to solve this issue.
It's not your fault - their certificate chain is not properly configured. What you can do is disabling the certificate verification (you should not do this when you're handling sensitive information!) but it might be fine for a webscraper.
page = requests.get(URL, verify=False)
enter image description here
Your SSL certificate is not installed properly , you can follow godaddy ssl install instruction maybe its helpfull .
https://in.godaddy.com/help/install-my-ssl-certificate-16623?sp_hp=B&xpmst=A&xpcarveout=B

SSLCertVerificationError while using Bert in ktrain package

I am using the ktrain package in jupyter with code supplied from this notebook. I get an error at the line qa = text.SimpleQA(INDEXDIR). The error is long but a shortened version is as follows:
HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/config.json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1125)')))
HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/config.json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1125)')))
OSError: Can't load config for 'bert-large-uncased-whole-word-masking-finetuned-squad'. Make sure that:
- 'bert-large-uncased-whole-word-masking-finetuned-squad' is a correct model identifier listed on 'https://huggingface.co/models'
- or 'bert-large-uncased-whole-word-masking-finetuned-squad' is the correct path to a directory containing a config.json file
I can access https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/config.json on my browser. I'm quite at a loss for what to do - my coding skills are minimal at best so any and all suggestions would be much appreciated.
My guess is that your corporate intranet is inserting a "man in the middle" on all https traffic. I'm guessing the following will give you the same error right now:
import requests
requests.get('https://www.huggingface.co')
If you get a CA certificate bundle from your IT department and you are on Windows, you can try this:
import os
os.environ['REQUESTS_CA_BUNDLE'] = 'path/to/certificates_ca_bundle.crt'
qa = text.SimpleQA(INDEXDIR)
If on Linux, install the certificates using these instructions.

Categories

Resources