[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

I’m new with mongodb. I’ve tried to add new entry and get this error.

[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

Are you getting this Compass or mongosh or in a program?
If your installation has a self-signed certificate, you have to tell MongoDB tooling where to get a copy of the acceptable certificate.
E.g., in PHP, you’d connect something like
new MongoDB\Client($mongodb_uri, b['tls' => true, 'tlsCAFile' => $mongodb_cert_path]);

I saw an answer that worked for me, it appears i had not yet installed the python certificates on my mac, so from the following path i went and installed it

/Applications/Python 3.10/Install Certificates.command

Only change the version of your python, after that everything, worked fine for me

PS: I had been trying to solve the problem for half a day, I even asked ChatGPT

enter image description here

Unfortunately that didn’t help

Using pyCharm, macOs Ventura 13.1

Full code:

from pymongo import MongoClient
cluster = MongoClient('mongodb+srv://pystudy:<password>@cluster0.fyglnvy.mongodb.net/?retryWrites=true&w=majority')
db = cluster['test']
collection = db['test']

post = {'_id': 0, 'name': 'Jeff', 'score': 9}
collection.insert_one(post)

open a new terminal and follow these (use “python” and “pip” if “python3” and “pip3” does not work):

  • create a test folder and cd into it: mkdir test && cd test
  • create clean environment python3 -m venv .venv (do MacOS use python or python3 for v3.x? )
  • and activate it: .venv/Scripts/activate
  • install pymongo only : pip3 install pymongo
  • you should see this clean list: pip3 list (versions might change)

    Package Version


    dnspython 2.3.0
    pip 22.2.2
    pymongo 4.3.3
    setuptools 63.2.0

  • and start python repl: python3
  • copy-paste your code above (replace password) and run in the repl.

if your code works this way, then the installation pycharm uses might be broken and need a repair or full reinstllation. (or pycharm is broken)

if not, then either your system has a problem or you messed with some settings in Atlas (I can’t point any).