Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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)
like image 911
Jack022 Avatar asked Dec 23 '22 02:12

Jack022


1 Answers

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

like image 145
Jack022 Avatar answered Dec 25 '22 14:12

Jack022