Server Selection TimeOut Error

1,860 views
Skip to first unread message

varsh...@gmail.com

unread,
Jul 11, 2017, 9:54:33 AM7/11/17
to mongodb-user
Hello Everyone,

I am new to Mongo db and I am tryign to pull the files out of Mongo DB using python Scripts.

 I am using RoboMongo as my client and connecting to a remote server from robo mongo.

When I am trying to execute the scripts,It is giving me an Error of Server Selection Timeout and I dont understand how to rectify it.

Can you please help me of how to get rid of that error.

Traceback (most recent call last):
  File "C:\Users\xsc7276\Desktop\trailsocket.py", line 17, in <module>
    for I in query:
  File "C:\Python27\lib\site-packages\pymongo\cursor.py", line 1114, in next
    if len(self.__data) or self._refresh():
  File "C:\Python27\lib\site-packages\pymongo\cursor.py", line 1036, in _refresh
    self.__collation))
  File "C:\Python27\lib\site-packages\pymongo\cursor.py", line 873, in __send_message
    **kwargs)
  File "C:\Python27\lib\site-packages\pymongo\mongo_client.py", line 888, in _send_message_with_response
    server = topology.select_server(selector)
  File "C:\Python27\lib\site-packages\pymongo\topology.py", line 214, in select_server
    address))
  File "C:\Python27\lib\site-packages\pymongo\topology.py", line 189, in select_servers
    self._error_message(selector))
ServerSelectionTimeoutError: localhost:27017: [Errno 10061] No connection could be made because the target machine actively refused it




Mycode



import pymongo
from pymongo import MongoClient
Client = MongoClient()
mydb = Client.DEFI
mycollection = mydb.defi_test
items = mycollection.find({})
print items
for document in items:
       print(document)

Rhys Campbell

unread,
Jul 12, 2017, 4:56:01 AM7/12/17
to mongodb-user
You say "connecting to a remote server" but your code reports "localhost:27017"  which is the default for MongoClient. Supply an appropriate hostname to MongoCLient

varsha J

unread,
Jul 13, 2017, 4:24:44 PM7/13/17
to mongod...@googlegroups.com
I tried it but it throws me the same error.



On Wed, Jul 12, 2017 at 03:56 'Rhys Campbell' via mongodb-user <mongod...@googlegroups.com> wrote:
You say "connecting to a remote server" but your code reports "localhost:27017"  which is the default for MongoClient. Supply an appropriate hostname to MongoCLient

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/viRHsCygDfU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/25916fa0-d212-439e-bca7-ed9f93c08c7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kevin Adistambha

unread,
Jul 24, 2017, 2:09:35 AM7/24/17
to mongodb-user

Hi

When I am trying to execute the scripts,It is giving me an Error of Server Selection Timeout and I dont understand how to rectify it.

ServerSelectionTimeoutError: localhost:27017: [Errno 10061] No connection could be made because the target machine actively refused it

That error is typically caused by trying to connect to a server that either has no MongoDB running, or the port is being blocked by a firewall. Could you please check that MongoDB is running, and you can connect to it using the mongo shell?

Also, this part in the code you posted:

Client = MongoClient()

Means that MongoClient will attempt to connect to localhost:27017 by default (see Pymongo MongoClient default values) as Rhys has mentioned. Have you modified the MongoClient() setting to point to the relevant server?

I tried it but it throws me the same error.

Could you post what you have tried and the error you see?

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages