简体   繁体   English

pymongo 和烧瓶的身份验证问题

[英]Authentication problems with pymongo and flask

I am trying to connect with pymongo and flask.我正在尝试连接 pymongo 和烧瓶。 I did this:我这样做了:

app.config['MONGO_HOST'] = 'ds02XX.mongolab.com'
app.config['MONGO_PORT'] = '29224'
app.config['MONGO_DBNAME'] = 'myusername'
app.config['MONGO_USERNAME'] = 'myusername'
app.config['MONGO_PASSWORD'] = 'thislongpasswordthatigotfrommongolab'

However, when I call mongo=PyMongo(app) , it simply does not work.但是,当我调用mongo=PyMongo(app) ,它根本不起作用。 and I get this error:我收到这个错误:

pymongo.errors.OperationFailure: command SON([('authenticate', 1), ('user', u'myusername'), ('nonce', u'somenumbers'), ('key', u'othernumbers')]) failed: auth failed

Is there anything I could do to check?有什么我可以做的检查吗? I used the same data to connect via mongo shell, and it worked fine!我使用相同的数据通过 mongo shell 进行连接,并且运行良好!

Thanks,谢谢,

Francis弗朗西斯

For some reason, PyMongo 3.0.3 is not working.出于某种原因,PyMongo 3.0.3 无法正常工作。 They - Mongolab - said that the drivers should be compatible with MongoDB 3.0, and PyMongo 3.0.3 is.他们 - Mongolab - 说驱动程序应该与 MongoDB 3.0 兼容,而 PyMongo 3.0.3 是。 I reverted back to PyMongo 2.8 and it works now.我恢复到 PyMongo 2.8,它现在可以工作了。

I got the same error message while using: MongoDB 2.6 and PyMongo 3.2.我在使用时收到相同的错误消息:MongoDB 2.6 和 PyMongo 3.2。 Tried downgrading my PyMongo to versiones 2.7 and 2.8, but was not working.尝试将我的 PyMongo 降级到 2.7 和 2.8 版本,但没有用。 Finally I got to connect successfully by updating my connection string to include the database.最后,我通过更新我的连接字符串以包含数据库来成功连接。

Changed from:更改自:

'mongodb://'+ MONGODB[ 'username' ] + ':' + MONGODB[ 'password' ] + '@' + MONGODB['server'] + ':' + MONGODB['port'] + '/'

to

'mongodb://'+ MONGODB[ 'username' ] + ':' + MONGODB[ 'password' ] + '@' + MONGODB['server'] + ':' + MONGODB['port'] + '/' + MONGODB['database']

MongoDB version 2.6 requires the connection strings to include the database if using credentials.如果使用凭据,MongoDB 2.6 版要求连接字符串包含数据库。 If database is not included, then the mongo client will try to authenticate and connect to a default admin database.如果不包含数据库,则 mongo 客户端将尝试进行身份验证并连接到默认的管理数据库。 It is detailed here . 这里有详细说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM