SSL handshake mongodb fail

I’m deploying Flask app via Web Service.
And need to use MongoDB as database.

Locally it works
But when on Render, it throws error:

"error": "SSL handshake failed: ac-zic2axe-shard-00-01.n3bexs7.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1006) (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms),SSL handshake failed: ac-zic2axe-shard-00-00.n3bexs7.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1006) (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms),SSL handshake failed: ac-zic2axe-shard-00-02.n3bexs7.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1006) (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms), Timeout: 30s, Topology Description: <TopologyDescription id: 663f390406f39995264645ac, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('ac-zic2axe-shard-00-00.n3bexs7.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('SSL handshake failed: ac-zic2axe-shard-00-00.n3bexs7.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1006) (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)')>, <ServerDescription ('ac-zic2axe-shard-00-01.n3bexs7.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('SSL handshake failed: ac-zic2axe-shard-00-01.n3bexs7.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1006) (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)')>, <ServerDescription ('ac-zic2axe-shard-00-02.n3bexs7.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('SSL handshake failed: ac-zic2axe-shard-00-02.n3bexs7.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1006) (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)')>]>"

I’ve set secret env in settings in Render, and locally I have it in .env
I also have it in docker, but not sure how to put those secret env in Docker in Render.



from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi


import os
from dotenv import load_dotenv, dotenv_values 
load_dotenv() 

# Render docs says I need to use: environ ? 
password = os.environ.get("PASSWORD_MONGODB") or os.getenv("PASSWORD_MONGODB") 
username =  os.environ.get("USERNAME_MONGODB") or os.getenv("USERNAME_MONGODB")



uri = f"mongodb+srv://{username}:{password}@cluster0.n3bexs7.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"

# Create a new client and connect to the server
client = MongoClient(uri, server_api=ServerApi('1'))

I needed to enable MongoDB connection from all IP hosts. In “network” tab…

Hi,

I replied to the ticket you also opened, I’ll repeat my response:

You likely need to allowlist the Render outbound IP with your MongoDB provider. Render outbound IPs and how to find them are covered in the docs here: https://docs.render.com/static-outbound-ip-addresses

Your community post shows you have opened your DB up to all IPs, you may want to restrict that to only the required IPs.

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