Authentication Failed When Using Flask_pymongo


Answer :

This question may be old, but I was experiencing the same issue and found another solution that might work for others.

Appending ?authSource=admin to the end of your MONGO_URI variable will authenticate your credentials against the admin database, rather than the one you're connecting to.

Example: app.config["MONGO_URI"] = "mongodb://username:password@host:port/db_name?authSource=admin"


The problem is if you use the MONGO_URI config parameter then pymongo attempts to authenticate against the db name included in the string. You should break up the config parameters into the following so you can specify a db name and an auth source.

app.config['MONGO_HOST'] = 'localhost' app.config['MONGO_PORT'] = '27017' app.config['MONGO_DBNAME'] = 'mongo_test' app.config['MONGO_USERNAME'] = 'root' app.config['MONGO_PASSWORD'] = 'aaa2016' app.config['MONGO_AUTH_SOURCE'] = 'admin' . # root user is typically defined in admin db 

Comments

Popular posts from this blog

Chemistry - Bond Angles In NH3 And NCl3

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Change The Font Size Of Visual Studio Solution Explorer