pymongo.errors.ServerSelectionTimeoutError: cluster0-shard-00-02.8axfw.mongodb.net:27017: [WinError 10054]

I am trying to connect my PYQT5 app to MongoDB my account is setup with the IP set correctly my code in my file looks like this.

from pymongo import MongoClient, DESCENDING
import certifi

cluster = MongoClient("mongodb+srv://TestDB:<xxxxxx>@cluster0.8axfw.mongodb.net/DATABASENAME?retryWrites=true&w=majority")
db = cluster["game"]  # select the database ...
collection = db["leaderboard"]  # this will be created if it doesn't exist!

# add a new score
x = {"id": 0, "user_name": "Leeeeroy Jenkins", "score": 124, "time": "11/24/2014 13:43:22"}
collection.insert_one(x)

I was having trouble earlier with different pip/ conda installations I needed to install but I have gotten passed that and now wen I run my code this error is printed.

Can someone please help me? I have been searching for a while here and on stack but nothing has fixed this error.

Hi @Liam_N_A - Welcome to the community!

It does look like your connection is attempted but is failing due to a timeout based off the error noted in the title.

From the client that is failing to connect, please try performing the initial basic network connectivity tests and provide the output for the cluster you are having trouble connecting to:

  1. ping one of the hosts (prefereably the PRIMARY):
/// example
ping cluster0-shard-00-00.ze4xc.mongodb.net
  1. telnet to one of the hosts on port 27017 :
/// example
telnet cluster0-shard-00-00.ze4cx.mongodb.net 27017

Note: You can find the hostname in the metrics page of your cluster

I would also try connecting using mongosh from the same client hosting the PYQT5 application you mentioned. If this also fails to connect, please provide the output from the connection attempt.

Additionally, I would recommend to review the Troubleshoot Connection Issues documentation and verify some configurations, such as adding the client’s IP (or IP ranges) to the Network Access List. You may also find the following blog post regarding tips for atlas connectivity useful.

Regards,
Jason