MongoDB and python using Motor, read and write operations to the database shows error

1.2k Views Asked by At

pymongo.errors.ServerSelectionTimeoutError: mflix-shard-00-00.fmraf.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129),mflix-shard-00-02.fmraf.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129),mflix-shard-00-01.fmraf.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: 60b1c9b0c4a5874ea362693e, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('mflix-shard-00-00.fmraf.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mflix-shard-00-00.fmraf.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')>, <ServerDescription ('mflix-shard-00-01.fmraf.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mflix-shard-00-01.fmraf.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')>, <ServerDescription ('mflix-shard-00-02.fmraf.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mflix-shard-00-02.fmraf.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')>]>

This is the error it is producing.

I am using FastApi, Motor, and uvicorn to the run server. The database I use is a free cluster provided in Mongo Atlas. It was working fine the last time I updated the server that is 2 days ago, but from yesterday onwards the error is produced. I've tried to update the above mentioned packages as of now.

I am new to mongodb.

1

There are 1 best solutions below

0
On

I have found a fix that works but I don't if its the best way.

client = motor.motor_asyncio.AsyncIOMotorClient(MONGO_DETAILS)

The above line is how I connected to my cluster. I changed the line to:

client = motor.motor_asyncio.AsyncIOMotorClient(MONGO_DETAILS, tls=True, tlsAllowInvalidCertificates=True)

It works as it did earlier there is no issue.

Anyway I would like to know why this error occurs!