MongoDB Atlas身份验证在Python上失败

时间:2018-12-08 12:43:34

标签: python mongodb heroku mongodb-atlas

我已将此Python应用程序部署在Heroku上,并且希望它连接到MongoDB Atlas集群。我使用我的字符串连接到集群,但是由于某种原因,我不断得到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) 的检查,并且用户名和密码均正确。为什么会这样?

.demo-row

3 个答案:

答案 0 :(得分:0)

愚蠢的错误,我必须键入MYPASSWORD而不是<MYPASSWORD>,而没有<>

答案 1 :(得分:0)

请勿在密码中使用任何特殊的字符,例如“ +”或“ =”。

我使用OpenSSL生成密码,例如u4wY9AOwnOLMY + h9EQ ==。遇到错误的身份验证身份验证失败。

使用MongoDB Compass后,它告诉我不要使用特殊字符,因此我删除了这些字符并使用了'u4wY9AOwnOLMYh9EQ'。

然后它起作用。

答案 2 :(得分:0)

检查从Mongodb Atlas Connections中选择的Python驱动程序版本的兼容性。 mongoengine flask不支持3.4以上的版本