[Pymongo] pymongo.errors.ServerSelectionTimeoutError: connection closed
See original GitHub issueHello 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:
- Created 4 years ago
- Comments:12
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 😃I’m having the same problem. Any solutions?