log4mongo / log4mongo-python

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

OperationFailure when trying to connect to an authenticated database #31

Closed gsmafra closed 7 years ago

gsmafra commented 7 years ago

I am trying to connect to an authenticated MongoDB instance where I don't have access to the admin database. I don't know if I'm misusing the package or this is a bug related to my specific configurations.

This is the most simple code to reproduce this behavior:

import logging
import log4mongo.handlers

logger = logging.getLogger('test')

handler = log4mongo.handlers.MongoHandler(
    host='host',
    port=27017,
    username='username',
    password='password',
    database_name='database_name',
    authentication_db='database_name',
)

logger.warning('test')

And this is the error:

/usr/local/lib/python3.6/dist-packages/log4mongo/handlers.py in __init__(self, level, host, port, database_name, collection, username, password, authentication_db, fail_silently, formatter, capped, capped_max, capped_size, reuse, **kwargs)
    121         self.capped_size = capped_size
    122         self.reuse = reuse
--> 123         self._connect(**kwargs)
    124 
    125     def _connect(self, **kwargs):

/usr/local/lib/python3.6/dist-packages/log4mongo/handlers.py in _connect(self, **kwargs)
    143                                              **kwargs)
    144                 try:
--> 145                     self.connection.is_locked
    146                 except ServerSelectionTimeoutError:
    147                     if self.fail_silently:

(...)

OperationFailure: not authorized on admin to execute command { currentOp: 1, $all: false }

I'm omitting the PyMongo stack trace for clarity. Any help would be appreciated.