uri = "mongodb+srv://username:password@clusterX.xxxxxxx.mongodb.net/?appName=ClusterX" client = MongoClient(uri, server_api=ServerApi('1'))
uri = "mongodb+srv://username:password@clusterX.xxxxxxx.mongodb.net/?appName=ClusterX" client = MongoClient(uri, server_api=ServerApi('1'))

I use the Python code above to establish a connection to the MongoDB server. It takes super long: 25 seconds.

When I use MongoDB VS Code Extension, I click the ‘Connect’ button and 1 second later the connection is established successfully.

Note: Same database, same PC, same IP.

What is the matter with the python code above? Any suggestions?