log4mongo / log4mongo-python

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

_connect error about authentication #33

Closed lamter closed 7 years ago

lamter commented 7 years ago

I got an error like this:

/Users/lamter/anaconda/envs/public/lib/python3.5/site-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 }

MongoClient.is_locked need auth of 'admin'. That will be correct without non-auth situation and with auth of database 'admin'. But when I pass 'username' and 'password' for database 'logs', it raised above error.

I deal with a non-recommendable way like this:

import pymongo
import log4mongo.handlers
import logging

log4mongo.handlers._connection = pymongo.MongoClient(
    host='localhost',
    port=30020,
)

mh = log4mongo.handlers.MongoHandler(
    host='localhost',
    port=30020,
    username='slavel',
    password='slavel',
    database_name='log',
    collection='testlog',
    authentication_db='log',
)

logger = logging.getLogger()
logger.addHandler(mh)

logger.warning('qwe')
oz123 commented 7 years ago

Latest commit changes that https://github.com/log4mongo/log4mongo-python/commit/470bfc391d50921a4130c6ea3b26eaf558adb76f

See if this solves the issue

gsmafra commented 7 years ago

@oz123 when will the current master version be available on PyPI? This issue is preventing me (and others I imagine) from using log4mongo at the moment.

oz123 commented 7 years ago

@gsmafra I will upload a new version next week. When it's done I will close the issue.

oz123 commented 7 years ago

@gsmafra I uploaded a new version (1.6.1) to PyPI.