MongoDB Atlas ServerSelectionTimeoutError: SSL handshake failed

Question:

I’m having a hard time fetching some data from my mongodb database using pymongo driver. I keep getting the following error:

pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed: ac-mtxrap4-shard-00-01.vfg8vpd.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1007),SSL handshake failed: ac-mtxrap4-shard-00-00.vfg8vpd.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1007),SSL handshake failed: ac-mtxrap4-shard-00-02.vfg8vpd.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1007), Timeout: 30s, Topology Description: <TopologyDescription id: 64f0dc87584d8256bd425707, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('ac-mtxrap4-shard-00-00.vfg8vpd.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('SSL handshake failed: ac-mtxrap4-shard-00-00.vfg8vpd.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1007)')>, <ServerDescription ('ac-mtxrap4-shard-00-01.vfg8vpd.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('SSL handshake failed: ac-mtxrap4-shard-00-01.vfg8vpd.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1007)')>, <ServerDescription ('ac-mtxrap4-shard-00-02.vfg8vpd.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('SSL handshake failed: ac-mtxrap4-shard-00-02.vfg8vpd.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1007)')>]>

I use linux ubuntu 22.04. Python version 3.10.12 and pymongo version 4.5.0

from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
from pymongo import database
from credentials import mongoDB_uri
import json
from bson import json_util

client = MongoClient(mongoDB_uri, server_api=ServerApi('1'))

class mongoDB:
    def __init__(self, client=client):
        self.client = client
        
    def getImageMetadata(self):
        db = database.Database(client=self.client, name="productimagedata")
        cl = db.get_collection(name="images")
        imageMetaData = []

        for obj in cl.find():
            imageMetaData.append(obj)

        return json.loads(json_util.dumps(imageMetaData))

There’s my code just in case, but I’m almost 100% sure it isn’t the issue with my script.

I also must mention that my code worked completely fine just a few days ago.

On google I couldn’t find any relevant solution that would work.
I tried:

  • Updating python to version 3.11.2
  • Assigning certifi.where() (perhaps, ssl certificate path) to tlsCAFile property of MongoClient instance as suggested here
  • Even setting ssl=False which didn’t work (probably because it isn’t the certificate issue as occurs to me)
  • Researching on TLSV1_ALERT_INTERNAL_ERROR, but couldn’t find anything that explains what’s going on better than this answer

Curious if anyone had encountered this kind of error before and can help with a solution.

Asked By: bonbon

||

Answers:

I have encountered this kind of error before make sure you do not have any VPN running on your computer. Moreover, check mongoDB atlas network settings check that your IP is allowed. Sometimes, this error occurs for apparently no reason as it was the case with me but it does not occur if you try sometime later.

Answered By: pekka 123
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.