Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to MongoDB 2.0.5 database with pymongo 2.2

I've been stuck with diagnosing this for a few hours now and thought I'd see if any pymongo experts out there have any ideas:

The following line of code:

connection = pymongo.Connection('localhost', 27017)

Generates the following error:

/usr/local/Cellar/python/2.7.3/bin/python2.7 /Users/danwilson/Dropbox/Projects/mysite/app.py
Traceback (most recent call last):
File "/Users/danwilson/Dropbox/Projects/mysite/app.py", line 149, in
main()
File "/Users/danwilson/Dropbox/Projects/mysite/app.py", line 144, in main
http_server = tornado.httpserver.HTTPServer(Application())
File "/Users/danwilson/Dropbox/Projects/mysite/app.py", line 54, in init
self.connection = pymongo.Connection('localhost', 27017)
File "/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/pymongo/connection.py", line 290, in init
self.__find_node()
File "/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/pymongo/connection.py", line 586, in __find_node
raise AutoReconnect(', '.join(errors))
pymongo.errors.AutoReconnect: 'module' object has no attribute 'decode_all'

mongod's streaming output acknowledges the connection:

My-MacBook-Pro:~ username$ mongod
mongod --help for help and startup options
Tue May 15 07:53:50 [initandlisten] MongoDB starting : pid=2277 port=27017 dbpath=/data/db/ 64-bit host=My-MacBook-Pro.local
Tue May 15 07:53:50 [initandlisten] db version v2.0.5, pdfile version 4.5
Tue May 15 07:53:50 [initandlisten] git version: 1bb4de4630302fad8af53824ca4f627db490b753
Tue May 15 07:53:50 [initandlisten] build info: Darwin erh2.10gen.cc 9.8.0 Darwin Kernel
Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_40
Tue May 15 07:53:50 [initandlisten] options: {}
Tue May 15 07:53:50 [initandlisten] journal dir=/data/db/journal
Tue May 15 07:53:50 [initandlisten] recover : no journal files present, no recovery needed
Tue May 15 07:53:50 [websvr] admin web console waiting for connections on port 28017
Tue May 15 07:53:50 [initandlisten] waiting for connections on port 27017
Tue May 15 07:53:57 [initandlisten] connection accepted from 127.0.0.1:50263 #1
Tue May 15 07:53:57 [conn1] end connection 127.0.0.1:50263

Package Versions

My-MacBook-Pro:~ username$ pip freeze
PyYAML==3.10
bson==0.3.3
distribute==0.6.26
mimeparse==0.1.3
pymongo==2.2
python-dateutil==2.1
pytz==2012c
six==1.1.0
tornado==2.2.1
virtualenv==1.7.1.2
wsgiref==0.1.2

MongoDB version

My-MacBook-Pro:~ username$ brew info mongodb
mongodb 2.0.5-x86_64
http://www.mongodb.org/
/usr/local/Cellar/mongodb/2.0.5-x86_64 (17 files, 121M) *
https://github.com/mxcl/homebrew/commits/master/Library/Formula/mongodb.rb

like image 261
SeaTurtle Avatar asked May 15 '12 15:05

SeaTurtle


Video Answer


1 Answers

The solution to this problem was not good news for pip: I had to uninstall pymongo and bson, then reinstall bson, then pymongo. So it looks like the order of installation is actually important!

like image 127
SeaTurtle Avatar answered Oct 03 '22 08:10

SeaTurtle