Can connect to server using mongo or telnet but can't using pymongo

2,149 views
Skip to first unread message

Alex Dong

unread,
Jun 28, 2010, 6:24:58 AM6/28/10
to mongodb-user
Hi there,

I'm having two servers: clifton and fairfield. MongoDb is running on
clifton. I have configured the firewall so that clifton will accept
traffic from fairfield targeting port 27017. (Yes, I've double-checked
mongodb.conf to make sure mongo is listening on 27017).

Now the weird thing is this: on fairfield, if I try to connect to
mongodb on clifton using `telnet clifton 27017` or `mongo clifton/
test`, I can get a connection without any problem. But if I tried to
do so using pymongo, I'll get this error message:

{{{
In [1]: from pymongo.connection import Connection
In [2]: Connection('clifton', 27017)
---------------------------------------------------------------------------
AutoReconnect Traceback (most recent call
last)


/usr/local/lib/python2.6/dist-packages/pymongo-1.7-py2.6-linux-
x86_64.egg/pymongo/connection.py in __init__(self, host, port,
pool_size, auto_start_request, timeout, slave_okay, network_timeout,
document_class, _connect)
183
184 if _connect:
--> 185 self.__find_master()
186
187 @staticmethod

/usr/local/lib/python2.6/dist-packages/pymongo-1.7-py2.6-linux-
x86_64.egg/pymongo/connection.py in __find_master(self)
450 sock.close()
451 if sock_error or self.__host is None:
--> 452 raise AutoReconnect("could not find master")
453 raise ConfigurationError("No master node in %r. You
must specify "
454 "slave_okay to connect to "

AutoReconnect: could not find master
}}}

My environment:
Ubuntu 9.10
MongoDB: 1.5.3
Pymongo: 1.7

Any hints?

Alex

Michael Dirolf

unread,
Jun 28, 2010, 10:55:50 AM6/28/10
to mongod...@googlegroups.com
When you connect w/ the shell can you successfully perform operations
(i.e. try saving a document and doing a findOne)?

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Rich Shea

unread,
Jun 29, 2010, 10:00:06 AM6/29/10
to mongodb-user
I've seen a similar case on one of my client machines. I found that I
needed to run python as superuser ('sudo python') on that machine in
order for the connection to work. I figured that I had installed
something slightly differently on that machine, but have never gone
back to figure out what. This has only happened on one machine of many
(all Ubuntu 9.10).

Лоик

unread,
Jun 29, 2010, 12:41:53 PM6/29/10
to mongod...@googlegroups.com
You installed/run pymongo from a virtual env or from the distro environment. I never had any issue like that. I run all my projects from virtual env. Still a bit weird that it would need to run as root.

Rich, that's a bit weird. If you don't run it as root. Does it work sometimes or it never connect? I don't see any reason for pymongo to be ran as root.

Loïc

Rich Shea

unread,
Jun 30, 2010, 9:33:14 AM6/30/10
to mongodb-user
fwiw - in my case that I mentioned, on the particular machine I am
always required to run python as root to connect via pymongo. For my
application I actually run pymongo within a daemon that is running as
a user in the sudo group, so I didn't encounter the problem until I
was using the python shell and manually creating the connection to the
database.
Reply all
Reply to author
Forward
0 new messages