我正在运行Mongo 2.2.0,进行分片和复制,并且使用python(pymongo 2.1.1)时有一些奇怪的行为。
注意事项:
在我尝试访问的每个数据库上创建了具有正确权限的用户。
以下是通过mongo路由器连接。
MONGO_URI是部署中早期设置的env变量:$ MONGO_URI =“mongodb:// USER:PASSWORD @ localhost:27017 / DB”
我可以通过mongo shell认证,读取和写入,我也可以启动python会话,以下工作正常:
>>> import pymongo
>>> import os
>>> c = pymongo.Connection(os.environ['MONGODB_URI'])
>>> c.DB.COLL.insert(dict(a=2))
>>> list(c.DB.COLL.find())
但是当我在插入时使用safe = True时
>>> import pymongo
>>> import os
>>> c = pymongo.Connection(os.environ['MONGODB_URI'])
>>> c.DB.COLL.insert(dict(a=2), safe=True)
我收到此错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "local/lib/python2.7/site-packages/pymongo/collection.py", line 312, in insert
continue_on_error, self.__uuid_subtype), safe)
File "local/lib/python2.7/site-packages/pymongo/connection.py", line 822, in _send_message
return self.__check_response_to_last_error(response)
File "local/lib/python2.7/site-packages/pymongo/connection.py", line 759, in __check_response_to_last_error
helpers._check_command_response(error, self.disconnect)
File "local/lib/python2.7/site-packages/pymongo/helpers.py", line 128, in _check_command_response
raise OperationFailure(msg % response["errmsg"])
pymongo.errors.OperationFailure: unauthorized
我是否以错误的方式调用了某些内容,或者某个地方是否存在auth和安全漏洞?我倾向于首先相信自己的错误,但如果我在插入语句中保留安全,我会得到正确的行为。
我已经研究过这些主题:
Pymongo gives db assertion failure while trying to access remote server Pymongo permissions issue for safe inserts OperationFailure: database error when threading in MongoEngine/PyMongo
...但我没有找到一个不需要我停用身份验证的答案。
编辑: 我也在googlegroup上发布并得到了我的回答,这是pymongo中的一个错误。我升级到2.3,一切都像预期的一样。
https://groups.google.com/forum/?fromgroups=#!topic/mongodb-user/UlbW4942xsw