Python Pymongo auth失败了

时间:2014-05-15 15:42:22

标签: python mongodb pymongo

Pymongo一直未能登录MongoDB。我为" root"键入了正确的密码帐户。

Traceback (most recent call last):
  File "index.py", line 3, in <module>
    from apis import app
  File "/home/app/apis/__init__.py", line 16, in <module>
    import apis.call
  File "/home/app/apis/call.py", line 12, in <module>
    import auth
  File "/home/app/apis/auth.py", line 18, in <module>
    connection.api.authenticate(database.ADMIN_ID,database.ADMIN_PASSWD)
  File "/usr/lib64/python2.6/site-packages/pymongo/database.py", line 875, in authenticate
    self.connection._cache_credentials(self.name, credentials)
  File "/usr/lib64/python2.6/site-packages/pymongo/mongo_client.py", line 456, in _cache_credentials
    auth.authenticate(credentials, sock_info, self.__simple_command)
  File "/usr/lib64/python2.6/site-packages/pymongo/auth.py", line 243, in authenticate
    auth_func(credentials[1:], sock_info, cmd_func)
  File "/usr/lib64/python2.6/site-packages/pymongo/auth.py", line 222, in _authenticate_mongo_cr
    cmd_func(sock_info, source, query)
  File "/usr/lib64/python2.6/site-packages/pymongo/mongo_client.py", line 687, in __simple_command
    helpers._check_command_response(response, None, msg)
  File "/usr/lib64/python2.6/site-packages/pymongo/helpers.py", line 178, in _check_command_response
    raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: command SON([('authenticate', 1), ('user', u'root'), ('nonce', u'9e44852e6597a1de'), ('key', u'f132369d21874c9858409e235abff25f')]) failed: auth failed

这是pymongo

import pymongo

connection = pymongo.MongoClient("127.0.0.1")
connection.api.authenticate("root","1234")
db = connection.api

pymongo在密码上使用md5吗?看起来mongodb数据中有一些不同的密码。

这里是mongodb admin system.users data

{   &#34;用户&#34;:&#34; root&#34;,   &#34; pwd&#34;:&#34; cde0d84e6749c235a3b4e36d945eb6fe&#34;,   &#34;角色&#34;:[     &#34; userAdminAnyDatabase&#34;   ] }

你看到了什么问题吗?

3 个答案:

答案 0 :(得分:11)

就我而言,我升级了pymongo

pip install --upgrade pymongo

答案 1 :(得分:0)

我尝试连接名为api的表。

connection.api.authenticate("root","1234")

api表中没有管理员帐户。我确实放入了system.admin表。所以,我在api表中创建了一个新的管理员帐户并且它有效。

答案 2 :(得分:0)

看起来您必须从Bluemix MongoDB凭据中删除证书,保存在文件(例如certificate.pem)中,并按如下方式引用它:

client = pymongo.MongoClient(uri_string, ssl_ca_certs='c:\data\certificate.pem')