Problem getting list_database_names() to return list with database names

When trying to use pymongo’s, myclient.list_database_names() it doesn’t return the list of databases connected to the server but rather just the MongoClient information. My team and I are making a pymongo resource file to use for robot framework tests, 2 images below are code snippets and we keep getting a timeout error when using list_database_names() even after setting up a successful connection.


When I run the list_database_names() function I get my list of databases returned. See below the example code / output.

client = MongoClient("mongodb://")
def listDatabases():
    names = client.list_database_names()
    return names
x = listDatabases()


['ZONES', 'address', 'admin', 'applications', 'browser', 'config', 'id_test', 'local', 'products', 'random', 'school', 'servers', 'temp_data', 'ttl', 'update', 'users', 'users2']

Can you verify the version of pymongo that you are using? And perhaps share the output you are getting from your command?

pymongo 4.1.1 and I get a server selection time out error, this is it:

ServerSelectionTimeoutError:: [Errno 11001] getaddrinfo failed, Timeout: 30.0s, Topology Description: <TopologyDescription id: 62b30bb5ef8befdc1c4a2a93, t
opology_type: Unknown, servers: [<ServerDescription () server_type: Unknown, rtt: None, error=AutoReconnect(: [Errno 11001
] getaddrinfo failed’)>]>

Would this be a server side problem or something with my code?
And thanks for the reply!

Seems to indicate a DNS resolution issue.

What URI are you using?