Having trouble authenticating to MongoDB - SCRAM-SHA-1 / MONGODB-CR Issue?

1,009 views
Skip to first unread message

Matt Spaeth

unread,
Mar 25, 2016, 12:14:47 PM3/25/16
to mongodb-user
I am getting the following error when trying to authenticate with a MongoDB 3.2.4 installation / Auth Schema version 5 (3.0 style). 

pymongo.errors.ConfigurationError: mechanism must be in ('GSSAPI', 'MONGODB-CR', 'MONGODB-X509', 'PLAIN')

This is how I'm connecting: 

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']]

I tried setting mechanism to MONGODB-CR: 

client.amazon.authenticate(settings['MONGODB_USER'], settings['MONGODB_PASSWORD'], mechanism='MONGODB-CR')

And that changes the error to this:

pymongo.errors.OperationFailure: command SON([('authenticate', 1), ('user', u'username'), ('nonce', u'nonce_value), ('key', u'key_value')]) failed: auth failed

I am new to MongoDB, so sorry if I am missing something. I appreciate any help you can offer. Thank you. 


Markus Thielsch

unread,
Mar 30, 2016, 9:10:16 PM3/30/16
to mongodb-user

Hi 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

Reply all
Reply to author
Forward
0 new messages