MongoEngine - Another user is already authenticated to this database. You must logout first

2024/9/8 8:37:27

Can anyone please explain why I am getting error Another user is already authenticated to this database. You must logout first when connecting to MongoDB using Flask MongoEngine?

from mongoengine.connection import get_db
from flask import Flask, jsonify, abort
from flask_cors import CORS
from flask_mongoengine import MongoEngine
from flask_restful import Apidef init_db():return MongoEngine()app = Flask(__name__)
CORS(app)
api = Api(app)
app.config.from_object('conf.settings')
db = init_db()
db.init_app(app)@app.route('/health_check')
def on_health_check():try:db = get_db()db.command('dbstats')return jsonify(status=200)except Exception as e:logging.exception('on_health_check() exception -> {}'.format(str(e)))abort(500, 'Could not connect to database')app.run(host='0.0.0.0', port=5000, debug=True, threaded=True)

conf/settings.py:

MONGODB_SETTINGS = {'host': 'mongodb://username:[email protected]:27017,mongo-rep-mongodb-replicaset-1.local:27017/db_name?replicaSet=whatever'
}

When I go to http://localhost:5000/health_check, it always throws the Exception with message as I described above.

Answer

So I was running into the same issue today, but ended up resolving it by installing a previous version of pymongo, e.g. pip install pymongo==3.4.0 instead of the latest version 3.7.0. There might be a bug...

https://en.xdnf.cn/q/72908.html

Related Q&A

How to bucketize a group of columns in pyspark?

I am trying to bucketize columns that contain the word "road" in a 5k dataset. And create a new dataframe. I am not sure how to do that, here is what I have tried far : from pyspark.ml.featur…

Dictionary of tags in declarative SQLAlchemy?

I am working on a quite large code base that has been implemented using sqlalchemy.ext.declarative, and I need to add a dict-like property to one of the classes. What I need is the same as in this ques…

How to connect to a GObject signal in python, without it keeping a reference to the connecter?

The problem is basically this, in pythons gobject and gtk bindings. Assume we have a class that binds to a signal when constructed:class ClipboardMonitor (object):def __init__(self):clip = gtk.clipboar…

openpyxl please do not assume text as a number when importing

There are numerous questions about how to stop Excel from interpreting text as a number, or how to output number formats with openpyxl, but I havent seen any solutions to this problem:I have an Excel s…

NLTK CoreNLPDependencyParser: Failed to establish connection

Im trying to use the Stanford Parser through NLTK, following the example here.I follow the first two lines of the example (with the necessary import)from nltk.parse.corenlp import CoreNLPDependencyPars…

How to convert hex string to color image in python?

im new in programming so i have some question about converting string to color image.i have one data , it consists of Hex String, like a fff2f3..... i want to convert this file to png like this.i can c…

How to add values to a new column in pandas dataframe?

I want to create a new named column in a Pandas dataframe, insert first value into it, and then add another values to the same column:Something like:import pandasdf = pandas.DataFrame() df[New column].…

value error happens when using GridSearchCV

I am using GridSearchCV to do classification and my codes are:parameter_grid_SVM = {dual:[True,False],loss:["squared_hinge","hinge"],penalty:["l1","l2"] } clf = …

How to remove english text from arabic string in python?

I have an Arabic string with English text and punctuations. I need to filter Arabic text and I tried removing punctuations and English words using sting. However, I lost the spacing between Arabic word…

python module pandas has no attribute plotting

I am a beginner of Python. I follow the machine learning course of Intel. And I encounter some troubles in coding. I run the code below in Jupyter and it raises an AttributeError.import pandas as pd st…