简体   繁体   English

MongoDB Atlas 身份验证在 Python 上失败

[英]MongoDB Atlas authentication failed on Python

I have deployed this Python app on Heroku and i want it to connect to a MongoDB Atlas cluster.我已经在 Heroku 上部署了这个 Python 应用程序,我希望它连接到 MongoDB Atlas 集群。 I used my string to connect to the cluster, but for some reason i keep getting raise OperationFailure(msg % errmsg, code, response) pymongo.errors.OperationFailure: bad auth Authentication failed.我使用我的字符串连接到集群,但由于某种原因,我不断收到raise OperationFailure(msg % errmsg, code, response) pymongo.errors.OperationFailure: bad auth Authentication failed. I checked twice and both the user and the password are correct.我检查了两次,用户名和密码都正确。 Any idea on why this is happening?知道为什么会这样吗?

from pymongo import MongoClient
import time
import random
import time
import datetime


client = MongoClient('mongodb+srv://USER:<MYPASSWORD>@test-2liju.mongodb.net/test?retryWrites=true')

db = client.one

mycol = client["tst"]


while True:


    test = int(random.randrange(-99999990,90000000,1))

    dic = {"num": test}

    result = db.tst.insert_one(dic)


    print(test)
    time.sleep(5)

愚蠢的错误,我不得不输入MYPASSWORD而不是<MYPASSWORD> ,没有<>

Don't use any special char in password, like '+' or '='.不要在密码中使用任何特殊字符,例如“+”或“=”。

I use OpenSSL to generate a password like u4wY9AOwnOLMY+h9EQ==.我使用 OpenSSL 生成像 u4wY9AOwnOLMY+h9EQ== 这样的密码。 Came across bad auth Authentication failed.遇到错误的身份验证身份验证失败。

After using MongoDB Compass it told me don't use special char, so I remove those and use like 'u4wY9AOwnOLMYh9EQ'.使用 MongoDB Compass 后,它告诉我不要使用特殊字符,所以我删除了它们并使用像 'u4wY9AOwnOLMYh9EQ'。

Then it works.然后它起作用了。

check the compatibility of the version of the Python driver you choose from the Mongodb Atlas Connections.检查您从 Mongodb Atlas Connections 中选择的 Python 驱动程序版本的兼容性。 versions above 3.4 are not supported by mongoengine flask mongoengine Flask 不支持 3.4 以上的版本

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

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