I’m struggling with this since yesterday, when I get my credentials from an external file, it becomes unable to authenticate, it shows this error:
pymongo.errors.OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
I tried to get my credentials from sqlite3, it didn’t work, i thought it was just a problem with sqlite, so I tried to do the same and store my credentials in a config file (.ini), and it doesn’t work either,
Even if I print the connection url, it is 100% correct, exactly the same I use when typing it manually and works.
# Get the MongoDB credentials from the config file
cparser = ConfigParser()
cparser.read(self.config)
USERNAME = quote_plus(cparser["MONGODB"]["USERNAME"])
PASSWORD = quote_plus(cparser["MONGODB"]["PASSWORD"])
CLUSTER = cparser["MONGODB"]["CLUSTER"]
# Preparing the database URL
uri = f'mongodb+srv://{USERNAME}:{PASSWORD}@{CLUSTER}/test?authSource=admin&replicaSet=atlas-itbq89-shard-0&readPreference=primary&ssl=true'
# Connecting to the MongoDB database
self.client = MongoClient(uri)
Hi @Doug_Duncan
Thank you for your response, but my password doesn’t have any special character, and even further, I already used the quote_plus() function that encode the username and password in case they contain any special character…
Well then, since it’s an authentication error, I would verify that the username and password in the config file are indeed correct by trying to connect with the mongosh shell (or the older mongo tool if you installed 5.0 or older).
Okay, this falls into the category of “impossible problems” IF you can print out the value uri from your example:
uri = f'mongodb+srv://{USERNAME}:{PASSWORD}@{CLUSTER}/test?authSource=admin&replicaSet=atlas-itbq89-shard-0&readPreference=primary&ssl=true'
print(uri)
AND IF you can then copy-and-paste what is printed to mongosh and it works THEN the entire world is falling apart and broken
But you may have to provide a concrete example because I for one cannot reproduce this bug. You’re going to have to prove it exists.
WELL, idk what to do to be honest, it doesn’t work on mongosh either, so that’s kinda relieving, but when typing this link letter by letter for example, it does work, is it something with the encoding ?
It is hard to say for sure, @Abdel , but I would guess that is the case.
It is possible that characters encoded two different ways would appear the same on the screen.