"Pymongo" Connection authentication Auth failed solution

Source: Internet
Author: User
Tags mongodb version

Story background:

I set up a MONGO database on the virtual machine (ip:192.168.xx.xx), and the contents are already stored. Inside a database called "adb", there is a collection, called "Acol"

I turned on MONGO's authentication feature and granted the user "UserA" access to "adb".

Then I connect it in the following way

Import'192.168.xx.xx'= Pymongo. Mongoreplicasetclient ('mongodb://%s:%[email protected]%s' %= conn["  adb"= db["acol"]

Result Error:

Pymongo.errors.OperationFailure:command SON ([' Authenticate ', 1), (' User ', U '), (' Nonce ', U '), (' Key ', U ')]) on names Pace Admin. $cmd Failed:auth Failed

Then, all sorts of entanglements. Later saw the official website, finally found a solution.

Http://api.mongodb.org/python/current/examples/authentication.html

1. View Pymongo Version: result is 3.2

Pip List-v

2. View MongoDB version: result is 2.6

Enter in the MONGO terminal

Db.version ()

MONGODB has a different authentication mechanism, the 3.0 version after the adoption of ' Scram-sha-1 ', the previous version of the use of ' MONGODB-CR '. So, in my version case, it's obvious that you should use ' MONGODB-CR '

Use the following method to connect, it succeeds.

' 192.168.xx.xx '  = Pymongo. Mongoclient (host) client.adb.authenticate ("UserA", "password", mechanism='mongodb-cr' = = db["Acol"]  

"Pymongo" Connection authentication Auth failed solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.