MongoDB Atlas身份验证在Python上失败 [英] MongoDB Atlas authentication failed on Python

查看:489
本文介绍了MongoDB Atlas身份验证在Python上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have deployed this Python app on Heroku and i want it to connect to a MongoDB Atlas cluster. 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. 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>,而没有<>

Stupid error, i had to type MYPASSWORD instead of <MYPASSWORD>, without the <>

这篇关于MongoDB Atlas身份验证在Python上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆