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
Post a Comment