Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MongoDB Atlas ServerSelectionTimeoutError: SSL handshake failed

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading