Raise ServerSelectionTimeoutError

Hi,
i’m studying and still discovering mongodb but it’s starting bad.
i have no problem to connect directly with compass but now i’m trying to connect and add data using python and it’s just giving me Timeout error.
i looked in other topics to solve the problem but nothing worked ( double clic on ‘Install Certificates.command’ too but nothing changed)
when i used an other mac everything worked well, the problem is just with mine.
so i’m using macOs if it matters and this is my code:

import datetime
from pymongo import MongoClient
client = MongoClient('mongodb+srv://hduser:********@cluster0.pvpgbwp.mongodb.net/test', 27017 )
coll = client.db.posts_dbo
doc = {"auteur":"Flouflou",
         "texte":"Mon premier post du mois",
         "tags":["python","mongodb"],
         "date":datetime.datetime.utcnow()
}
post_id = coll.insert_one(doc).inserted_id
print(post_id)

this is the error message:

pymongo.errors.ServerSelectionTimeoutError: ac-j3n0ofn-shard-00-00.pvpgbwp.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129),ac-j3n0ofn-shard-00-01.pvpgbwp.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129),ac-j3n0ofn-shard-00-02.pvpgbwp.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129), Timeout: 30s, Topology Description: <TopologyDescription id: 634edf87a414d0dc84a44689, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('ac-j3n0ofn-shard-00-00.pvpgbwp.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-j3n0ofn-shard-00-00.pvpgbwp.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')>, <ServerDescription ('ac-j3n0ofn-shard-00-01.pvpgbwp.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-j3n0ofn-shard-00-01.pvpgbwp.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')>, <ServerDescription ('ac-j3n0ofn-shard-00-02.pvpgbwp.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-j3n0ofn-shard-00-02.pvpgbwp.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')>]>

Process finished with exit code 1
so please if anyone can help thank you

Hi @Amine_Gharbi welcome to the community!

The error SSL: CERTIFICATE_VERIFY_FAILED was commonly due to outdated OS root certificate. Please have a look at the solution in Keep getting ServerSelectionTimeoutError - #10 by Priyanka_Priyadarshini and see if it helps.

Best regards
Kevin