[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

4 Likes

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).

This worked for me.
Thank you mate!

I had similar problems and it felt like I tried everything. MacOS Ventura 13.2.1, PyCharm 2022.3.3 Professional, Python 3.11.2

The final fix…

I rebooted!!!

So, some of these changes don’t take effect until a complete reboot.

1 Like

For me - After a few hours I found this thread that said that I need to open the client using certifi

Able to use Compass with no problems, Atlas UI all looks good but couldn’t connect using Python.

Using Python 3.11, pymongo==3.11, Mac Monterey, VS Code

As a newbie I am disappointed that I had to spend a lot of time on ChatGPT and Google to resolve this.
Not a fantastic first impression but happy to blame myself for something i missed - maybe others will miss whatever I missed too…

Thank you mate!

This worked for me.

1 Like

I had similar problems and it felt like I tried everything..

.

Thanks, worked for me!

Upgrading from pip3 23.2.1 to 24.0 fixed this issue for me. No clue why!

1 Like

Thank you, I had to do it after upgrading Python to 3.11

This worked for me

pip install certifi