question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Pymongo] pymongo.errors.ServerSelectionTimeoutError: connection closed

See original GitHub issue

Hello everybody! This is my first post, hope we can find the solution together!

Here in the company I work in we have this mongodb from another team of the same company. I’ve tried to connect to their db with the login and password they gave to me. Here’s a very simple code, that reflect the problem I’m having. When trying to connect I get this error. My final objective will be to extract an entire db in csv format, for our own purposes. It need to be done via python.

Any idea of what’s happening?

Thank you for your help.

My Code:

from pymongo import MongoClient
from pprint import pprint

mongodb_uri = "mongodb://<my_login>:<my_password>@<mongodb_path>:27017"
client = MongoClient(mongodb_uri)
db = client.ctox
serverStatusResult = db.command("serverStatus")
pprint(serverStatusResult)

The error:

File “C:\Users\matheus.silva\AppData\Local\Continuum\anaconda3\lib\site-packages\pymongo\database.py”, line 655, in command read_preference) as (sock_info, slave_ok): File “C:\Users\matheus.silva\AppData\Local\Continuum\anaconda3\lib\contextlib.py”, line 112, in enter return next(self.gen) File “C:\Users\matheus.silva\AppData\Local\Continuum\anaconda3\lib\site-packages\pymongo\mongo_client.py”, line 1135, in _socket_for_reads server = topology.select_server(read_preference) File “C:\Users\matheus.silva\AppData\Local\Continuum\anaconda3\lib\site-packages\pymongo\topology.py”, line 226, in select_server address)) File “C:\Users\matheus.silva\AppData\Local\Continuum\anaconda3\lib\site-packages\pymongo\topology.py”, line 184, in select_servers selector, server_timeout, address) File “C:\Users\matheus.silva\AppData\Local\Continuum\anaconda3\lib\site-packages\pymongo\topology.py”, line 200, in _select_servers_loop self._error_message(selector)) pymongo.errors.ServerSelectionTimeoutError: connection closed

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

40reactions
dementednoorcommented, Jan 12, 2020

I’m having the same problem. Any solutions?

https://stackoverflow.com/questions/55005134/app-engine-pymongo-errors-serverselectiontimeouterror-connection-closed-connec

I’ve faced the same problem when I tried to access my Mongo cluster from another machine. So I followed the steps above and fixed the problem. The solution is adding 0.0.0.0/0 to the IP Whitelist. It’s situated here: *Your Mongo cluster* -> Security -> Network Access -> IP Whitelist -> Add IP Address Not sure if it’s secure though, but at least fixes problem for kind of little pet-projects 😃

2reactions
yan-michaelcommented, Dec 29, 2019

I’m having the same problem. Any solutions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

App Engine, pymongo.errors.ServerSelectionTimeoutError
The problem was the Ip Whitelist, thus I have add via the vpc peering connection with gcp. To do simple, we can add...
Read more >
pymongo.errors.ServerSelectionTimeoutError with atlas even ...
This error means that pymongo timed out while waiting for a response from the remote server. Usually this means there is a network...
Read more >
[Solved] pymongo.errors.ServerSelectionTimeoutError
PyMongo cannot connect to any server. If you attempt an insert into a replica set that has no primary node. And the mongo...
Read more >
Using PyMongo to connect with Atlas cluster : r/mongodb
Hi, I have been trying to make Pymongo work with my free atlas cluster since a while now, but just reaching errors like:...
Read more >
App Engine, pymongo.errors.ServerSelectionTimeoutError ...
Coding example for the question App Engine, pymongo.errors.ServerSelectionTimeoutError: connection closed,connection closed,connection closed"-mongodb.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found