Mongo Insert failing when access MongoDB Atlas - PYTHON

Hi all, strange…
I have a MongoDB deployed on a EKS cluster in AWS, I can insert into it using a port forward (running code locally in test).
When I change my URL to point to a MongoDB Atlas created database, it connects, but then fails on the inserT_one …
I’m authenticating using username password, and for naughty set my network access to 0.0.0.0/0 at the moment.
copy/pasted the Atlas provided url.

any ideas popping up?
G

The update_one eventually fails with the below error…
MONGO_URL = cluster0.gqtnee8.mongodb.net # modified here of course :wink:

        uri = f'mongodb+srv://{MONGO_USERNAME}:{urllib.parse.quote_plus(MONGO_PASSWORD)}@{MONGO_URL}/?retryWrites=true&w=majority'

        myClient    = pymongo.MongoClient(uri)
        myDB        = myClient["trustreg]
        my_jwt_collection       = myDB["jwt_keys]
        
       pub_payload = {
            "originatingDate":  str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
            "endToEndId":       endToEndId,
        }
        with myClient.start_session() as my_session:

            my_jwt_collection.update_one({"id": pub_payload["id"]}, {"$set": pub_payload}, upsert=True, session=my_session)
            
        # end with

ERROR :2023-04-12 10:05:36.714821, Payload Save Failed!, endToEndId:4dc6c46fc2f8468 error:ac-ctpggnp-shard-00-01.gqtnee8.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129),ac-ctpggnp-shard-00-02.gqtnee9.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129),ac-ctpggnp-shard-00-00.gqtnee8.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: 643665d890e02ff9a91af488, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('ac-ctpggnp-shard-00-00.gqtnee9.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-ctpggnp-shard-00-00.gqtnee8.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')>, <ServerDescription ('ac-ctpggnp-shard-00-01.gqtnee8.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-ctpggnp-shard-00-01.gqtnee8.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')>, <ServerDescription ('ac-ctpggnp-shard-00-02.gqtnee8.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-ctpggnp-shard-00-02.gqtnee8.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')>]>

Resolved.

import certifi

        myClient    = pymongo.MongoClient(uri,
                                          serverSelectionTimeoutMS=5000,
                                          tlsCAFile=certifi.where())
1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.