Setting MongoDB authorization configuration in Python-Eve

我是研究僧i 提交于 2019-12-08 01:42:49

问题


I am using Python-Eve with a MongoDB instance with authorization enabled, so I need to provide user/pass credentials in settings.py to properly initialize Python-Eve API.

If used the MONGO_URI global configuration setting, to declare the database endpoint as described here it works just right:

MONGO_URI = 'mongodb://<someuser>:<somepass>@<host>/<auth_db>'

But if I try to use the other possible way according to Eve documentation, which is to declare at settings.py, individual settings for each part or the URI, like this:

MONGO_HOST = <host>
MONGO_PORT = 27017
MONGO_DBNAME = <mongo_db>
MONGO_USERNAME = <someuser>
MONGO_PASSWORD = <somepass>
MONGO_AUTHDBNAME = <auth_db>

I get an error like the one below:

pymongo.errors.OperationFailure: command SON([('saslStart', 1), ('mechanism', 'SCRAM-SHA-1'), ('autoAuthorize', 1), ('payload', Binary(b'n,,n=root,r=MzcxMTQ1MTM3MTExNDYwNg==', 0))]) on namespace testapp.$cmd failed: Authentication failed.

What is missing to make it work this way?


回答1:


OK I figured out what was wrong to make it work. The auth database that is used to check credentials is the same as MONGO_DBNAME, not MONGO_AUTH_DBNAME value. So in my example the users must exist in the <mongo_db> database, not in the <auth_db> as I was expecting.

But then, what is the purpose of MONGO_AUTHDBNAME setting?




回答2:


MONGO_AUTHDBNAME is useful for some old MongoDB authentication schemes which are now deprecated. For more information see the original pull request discussion.



来源:https://stackoverflow.com/questions/33870025/setting-mongodb-authorization-configuration-in-python-eve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!