SSL Certificate Verification Failure in WolframAlpha Python - python

So I'm currently trying to make a search engine that compiles data from multiple different databases and search engines, and everything has worked up until I tried to add the WolframAlpha API. When I try to run the WolframAlpha section of the code, it gives me about 20million lines of errors, but the most prominent ones seem to be:
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1108)>
and
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1108)
The relevant code is the standard script for WolframAlpha Python queries:
import wolframalpha
def wolframSearch():
client = wolframalpha.Client('wolfram-apikey')
query = input("Please Input Wolfram Query: ")
res = client.query(query)
output = next(res.results).text
print(output)
wolframSearch()
I'm currently using Python version 3.8 and I've already checked that the versions of all of the relevant modules and software

Related

Connect MongoDB to Python

I try to connect to MongoDB database from https://cloud.mongodb.com/
My code:
import pymongo
from pymongo.server_api import ServerApi
client = pymongo.MongoClient("mongodb+srv://<My-Username:<My-Password#test.umh3xqu.mongodb.net/?retryWrites=true&w=majority", server_api=ServerApi('1'))
print(client.list_database_names())`
Errors:
pymongo.errors.ServerSelectionTimeoutError: ac-gyw4foz-shard-00-01.umh3xqu.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992),ac-gyw4foz-shard-00-00.umh3xqu.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992),ac-gyw4foz-shard-00-02.umh3xqu.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED]
How to fix???
List all databases

Error in pytube <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>

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'

Unable to connect to GCP

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)

SSL: CERTIFICATE_VERIFY_FAILED certificate verify failed: Hostname mismatch, certificate is not valid for 'url''

I am trying to access Solr using urllib2 as instaructed here: https://lucene.apache.org/solr/guide/7_3/using-python.html using urllib
but running into error raise URLError(err) urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'the_dns-for-lb'
The cert exist in AWS ACM and there is custom auth, can someone guide me how to establish connection?
from urllib.request import urlopen
connection = urlopen('https://dns-for-lb/solr/design').read()
response = eval(connection.read())
tried:
Using urllib gives SSL error
Using urllib gives SSL error
pip install fails with "connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)"

httplib.HTTPSConnection issue : CERTIFICATE_VERIFY_FAILED

I'm trying to access a website with httplib library but i'm getting this error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)
c = httplib.HTTPSConnection('IP', 443)
c.request(method,url);
Because the certificate is self-signed. How can I disable the certificate verification?
Thanks!
How do I have python httplib accept untrusted certs?
httplib.HTTPSConnection(hostname, timeout=5, context=ssl._create_unverified_context())

Categories

Resources