Search code examples
pythonmongodbflaskmlab

Authentication problems with pymongo and flask


I am trying to connect with pymongo and flask. I did this:

app.config['MONGO_HOST'] = 'ds02XX.mongolab.com'
app.config['MONGO_PORT'] = '29224'
app.config['MONGO_DBNAME'] = 'myusername'
app.config['MONGO_USERNAME'] = 'myusername'
app.config['MONGO_PASSWORD'] = 'thislongpasswordthatigotfrommongolab'

However, when I call mongo=PyMongo(app), it simply does not work. and I get this error:

pymongo.errors.OperationFailure: command SON([('authenticate', 1), ('user', u'myusername'), ('nonce', u'somenumbers'), ('key', u'othernumbers')]) failed: auth failed

Is there anything I could do to check? I used the same data to connect via mongo shell, and it worked fine!

Thanks,

Francis


Solution

  • For some reason, PyMongo 3.0.3 is not working. They - Mongolab - said that the drivers should be compatible with MongoDB 3.0, and PyMongo 3.0.3 is. I reverted back to PyMongo 2.8 and it works now.