9
votes

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

1
Looks to me like bson isn't installed correctly as decode_all from your error message "pymongo.errors.AutoReconnect: 'module' object has no attribute 'decode_all'" is used in the bson library: api.mongodb.org/python/current/api/bson/index.html#module-bson.Niek de Klein
Hi Niek, yes I saw that, and I did already have bson installed. 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! Anyway, thanks for your help.SeaTurtle
I just had this exact problem - would this be an error with pip or pymongo being bundled wrong, maybe requiring the wrong bson version? (Disclaimer: I don't know anything about python packages)Alex Zylman
@AlexZylman Good to hear it's not just me, thanks!SeaTurtle

1 Answers

15
votes

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!