log4mongo / log4mongo-python

python logging handler for mongo database
http://log4mongo.org
Other
111 stars 37 forks source link

Pymongo has removed authenticate method in Database class but log4mongo is still using it which cause exception. #50

Closed codeworm47 closed 2 years ago

codeworm47 commented 2 years ago

I just install latest version of log4mongo which automatically installed pymongo as dependency. I got below error when instantiating MongoHandler :

TypeError: 'Collection' object is not callable. If you meant to call the 'authenticate' method on a 'Database' object it is failing because no such method exists.

Here is my code :

db_handler = MongoHandler(host=mongo_connection_params['host'], port=mongo_connection_params['port'], username=mongo_connection_params['username'], password=mongo_connection_params["password"], database_name=mongo_connection_params['db'], collection='logs')

It happens here actually :

if self.username is not None and self.password is not None: auth_db = self.connection[self.authentication_database_name] self.authenticated = auth_db.authenticate(self.username, self.password)

Looks like authenticate method has been removed in the later version of pymongo but log4mongo is still using it. This link also might help : https://debugah.com/solved-typeerror-collection-object-is-not-callable-if-you-meant-to-call-the-authenticate-method-on-a-database-object-it-is-failing-because-no-such-method-exists-23011/

codeworm47 commented 2 years ago

I resolved it by specifying Mongo URI as host parameter : db_handler = MongoHandler(host=os.environ[EnvVars.MONGO_URI], database_name=mongo_connection_params['db'], collection='logs')