Connect MongoDB to Python - 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

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?

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'

SSL Certificate Verification Failure in WolframAlpha 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

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