I am trying to connect to GCP where I have set up my file ("private_key_file") and trying to read the content within that file.
def gcsStorageClient(errLogRef):
try:
storage_client = storage.Client(os.environ.get("project_name"))
bucket = storage_client.get_bucket(os.environ.get("bucket_name"))
blob = bucket.get_blob(os.environ.get("private_key_file"))
file = blob.download_as_string()
return file
except Exception as error:
print("error:: " + error)
But I am seeing the below exception from my MAC OS which is related to SSL Verification, it seems like MAC firewall client is blocking the connect. Is there any way to say SSLVerify false or create a proxy to connect to GCP
exception: HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded
with url: /token (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate
verify failed (_ssl.c:852)
Is there any way to say SSLVerify false or create a proxy to connect to GCP?
PS: All environment values along with json file are already set into the running environment.
I ran into this recently. Running Install Certificates.command worked for me, but my python version is 3.6.8. I also changed repo python script manually to use python3 (changed #!/usr/bin/env python -> #!/usr/bin/env python3).
Please refer below link for more information:
Mac OSX python ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
Related
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'
Code:
from pytube import Playlist
playlist = Playlist('https://www.youtube.com/playlist?list=PLWPirh4EWFpEpO6NjjWLbKSCb-wx3hMql')
for video in playlist.videos:
print("Video: ",video)
video.streams.get_highest_resolution().download()
Error I am getting:
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
(for OSX users)
In another words...
Go to your applications folder and look for Python folder. Mine says "Python 3.11"
Open that directory, there is a file called "Install Certificates.command".
Open that file and it will run the command.
# Solved in
# add
import ssl
ssl._create_default_https_context = ssl._create_stdlib_context
Go to /Applications/Python3.x and run 'Install Certificates.command'
I need to call a web API. For that I need a bearer token.
I am using databricks(python) code to first get authenticated over Microsoft AAD. Then get bearer token for my service_user. I Followed the microsoft docs docs
But facing problem where it hits our Company server and asking for SSL certificate.
I can't install any certificate. What could be a better way to avoid it. Below is my short code taken from above microsoft and Git repos. but its not working.
Can i get help!
clientId = "42xx-xx-xx5f"
authority = "https://login.microsoftonline.com/tenant_id/"
app = msal.PublicClientApplication(client_id=clientId, authority=authority)
user = "serviceuser#company.com"
pwd = "password"
scope = "Directory.Read.All"
result = app.acquire_token_by_username_password(scopes=[scope], username=user, password=pwd)
print(result)
Got below error
HTTPSConnectionPool(host='mycompany.com', port=443): Max retries exceeded with url: /adfs/services/trust/mex (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1125)')))
The problem is that the code uses the requests library that relies on the certifi package instead of using Linux certificate chain (so existing instructions doesn't work). To solve that problem it's better to use cluster init script that will install SSL certificate when cluster starts. Something like this (requests and certifi are installed by default), just replace CERT_FILE with actual path to the .pem file with CA certificate:
CERT_FILE="/dbfs/....."
CERTIFI_HOME="$(python -m certifi 2>/dev/null)"
cat $CERT_FILE >> $CERTIFI_HOME
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.
I am new to Python, trying to read & parse logs of applications https url. My org has proxy setup. I am able to connect http url using basic_auth providing & & also by CA5 cert using below code
import urllib3
from urllib3 import ProxyManager, make_headers
# default_headers = make_headers(proxy_basic_auth='<username>:<password>')
# http = ProxyManager("http://<proxy_server>:<port>/", headers=default_headers)
http = ProxyManager("http://<proxy_server>:<port>/",cert_reqs='CERT_REQUIRED',ca_certs='<Windows path to .cer>')
r = http.request('GET','http://google.com')
print(r.data)
.pem certificate got saved as .cer on windows system.
This is working as excepted and returnign google data.
Now while trying to use same for HTTPS url using below,
r = http.request('GET','https://google.com',verify='<same as above i.e. Windows path to .cer>')
It is failing with below errors,
.
.
OSError: Tunnel connection failed: 502 notresolvable
.
.
.
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),))
As the log files are keeping updating, might need to stream it; Suggestion on this is highly appreciated.
Using Python 3.6.0 |Anaconda 4.3.1 (64-bit) on Windows 7.