Python Pymongo auth failed

梦想与她 提交于 2019-12-07 08:21:58

问题


Pymongo keep failing to login MongoDB. I typed right password for "root" account.

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

Here is pymongo

import pymongo

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

does pymongo use md5 on password? it looks like there is some different password in mongodb data.

here is mongodb admin system.users data

{ "user": "root", "pwd": "cde0d84e6749c235a3b4e36d945eb6fe", "roles": [ "userAdminAnyDatabase" ] }

Do you see what is wrong?


回答1:


In my case, I upgraded pymongo

pip install --upgrade pymongo



回答2:


I tried to connect table called api.

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

There wasn't admin account in api table. I did put in system.admin table. So, I created a new admin account in api table and it worked.




回答3:


Looks like you have to cut the certificate from the Bluemix MongoDB Credentials, save in a file (e.g. certificate.pem), and refer to it as follows:

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



来源:https://stackoverflow.com/questions/23682933/python-pymongo-auth-failed

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