pymongo.errors.ConfigurationError: mechanism must be in ('GSSAPI', 'MONGODB-CR', 'MONGODB-X509', 'PLAIN')def __init__(self):
client = pymongo.MongoClient(
settings['MONGODB_SERVER'],
settings['MONGODB_PORT']
)
client.amazon.authenticate(settings['MONGODB_USER'], settings['MONGODB_PASSWORD'])
db = client[settings['MONGODB_DB']]
self.collection = db[settings['MONGODB_COLLECTION']]client.amazon.authenticate(settings['MONGODB_USER'], settings['MONGODB_PASSWORD'], mechanism='MONGODB-CR')pymongo.errors.OperationFailure: command SON([('authenticate', 1), ('user', u'username'), ('nonce', u'nonce_value), ('key', u'key_value')]) failed: auth failedHi Matt,
Judging from this error message
pymongo.errors.ConfigurationError: mechanism must be in ('GSSAPI', 'MONGODB-CR', 'MONGODB-X509', 'PLAIN')
I assume you are using a PyMongo version <2.8 - Please note that to be able to utilise all functionality of the MongoDB version you are using (3.2.4) I highly recommend using PyMongo 3.2 (note that the matchup of version numbers is coincidental).
Please have a look at our Python Compatibility chart for further clarification.
You can check the version of PyMongo in your python compiler with this simple example:
>>> import pymongo
>>> pymongo.version
>>> '3.2.2'
If you are running a lower version than the latest available please have a look at the PyMongo Install / Upgrade documentation.
As for your question I was not able to reproduce your mechanism error messages unless I set the authentication mechanism to a non existing option. That makes me wonder if there is something else somewhere in your code which sets this and when using mechanism='MONGODB-CR' gets overwritten.
I also noticed in your code that you are always trying to authenticate to a database called amazon. If this is intended you need to make sure the user you are authenticating exists within the database. Please also note that the mongod log will give you more info as to why the authentication failed.
For more information on security within MongoDB have a look at our Authentication documentation.
Regards,
Markus