'Pymongo and Atlas server selection timeout can't connect both with tls or not
I've installed pymongo using python3 -m pip install pymongo[srv].
I'm trying to connecting to my atlas database using the following python3 code:
#!/usr/bin/env python3
import logging
import sys
from pymongo import MongoClient
import pymongo
from pymongo.server_api import ServerApi
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
try:
client = pymongo.MongoClient(
"mongodb+srv://user:[email protected]/?retryWrites=true&w=majority",
27017,
tls=True,
tlsAllowInvalidCertificates=True)
logger.info("Connected")
logger.info(client.list_database_names())
logger.info("Tested")
except Exception as ex:
logger.error("*** ERROR ***")
logger.error(ex)
sys.exit(1)
But I get always those errors:
2022-05-18 18:18:29,454 - __main__ - INFO - Connected
2022-05-18 18:18:59,523 - __main__ - ERROR - *** ERROR ***
2022-05-18 18:18:59,523 - __main__ - ERROR - cluster0-shard-00-02.ut26d.mongodb.net:27017: timed out,cluster0-shard-00-00.ut26d.mongodb.net:27017: timed out,cluster0-shard-00-01.ut26d.mongodb.net:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 62851c55fe574434a2378d31, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('cluster0-shard-00-00.ut26d.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('cluster0-shard-00-00.ut26d.mongodb.net:27017: timed out')>, <ServerDescription ('cluster0-shard-00-01.ut26d.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('cluster0-shard-00-01.ut26d.mongodb.net:27017: timed out')>, <ServerDescription ('cluster0-shard-00-02.ut26d.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('cluster0-shard-00-02.ut26d.mongodb.net:27017: timed out')>]>
I can't figure out where I'm wrong...
In mongo db atlas I've opened the access from everywhere and my username and password have simple chars that doesn't needs to be parsed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
