I am getting selection timeout error when i am trying to load the json file into the database

This is my code to write into database***************
import json
from pymongo import *
dns = MongoClient(“mongodb+srv://m001-student:m001-mongodbstudent@sandbox.bihwd.mongodb.net/?retryWrites=true&w=majority”)
def InsertIntoDb(database,coll):
db = dns[database]
Collection = db[coll]

with open('fandata.json') as file:

    f = json.load(file)

    Collection.insert_many(f)

file.close()

InsertIntoDb(‘company’,‘customers’)
This is the error i am getting****************
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: sandbox-shard-00-00.bihwd.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129),sandbox-shard-00-02.bihwd.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129),sandbox-shard-00-01.bihwd.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129), Timeout: 30s, Topology Description: <TopologyDescription id: 62d95e5bfd1449c82827d381, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription (‘sandbox-shard-00-00.bihwd.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘sandbox-shard-00-00.bihwd.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)’)>, <ServerDescription (‘sandbox-shard-00-01.bihwd.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘sandbox-shard-00-01.bihwd.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)’)>, <ServerDescription (‘sandbox-shard-00-02.bihwd.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘sandbox-shard-00-02.bihwd.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)’)>]>


i am trying to write a json file called fandata.json. where i am loading the data and using .insert_many() function to insert.
please do help me

Hi @Sai_Gokul_K_P

Are you still seeing this error?

There’s a topic with a similar error message to what you’re seeing some time ago. Perhaps you can try the solution in that topic? https://www.mongodb.com/community/forums/t/ticket-connection-ssl-certificate-verify-failed/91943

If it still doesn’t work out for you, could you post:

  • Your Python & Pymongo versions
  • Your OS
  • Whether you can connect successfully using the mongo shell (mongo or mongosh)

Best regards
Kevin