MongoDB Atlas 身份验证在 Python 上失败

Jac*_*022 4 python heroku mongodb mongodb-atlas

我已经在 Heroku 上部署了这个 Python 应用程序,我希望它连接到 MongoDB Atlas 集群。我使用我的字符串连接到集群,但由于某种原因,我不断raise OperationFailure(msg % errmsg, code, response) pymongo.errors.OperationFailure: bad auth Authentication failed.检查两次,并且用户和密码都正确。知道为什么会这样吗?

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)
Run Code Online (Sandbox Code Playgroud)

Jac*_*022 10

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