Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not authorized on admin [ Mongo version : 3.4.4 ] #27

Open
sreecodeslayer opened this issue May 9, 2017 · 5 comments
Open

Not authorized on admin [ Mongo version : 3.4.4 ] #27

sreecodeslayer opened this issue May 9, 2017 · 5 comments

Comments

@sreecodeslayer
Copy link

Issue :

File "/usr/local/lib/python2.7/dist-packages/log4mongo/handlers.py", line 123, in __init__
    self._connect(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/log4mongo/handlers.py", line 145, in _connect
    self.connection.is_locked
  File "/home/sreenadh/.local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 1186, in is_locked
    ops = self._database_default_options('admin').current_op()
  File "/home/sreenadh/.local/lib/python2.7/site-packages/pymongo/database.py", line 620, in current_op
    return sock_info.command("admin", cmd)
  File "/home/sreenadh/.local/lib/python2.7/site-packages/pymongo/pool.py", line 239, in command
    read_concern)
  File "/home/sreenadh/.local/lib/python2.7/site-packages/pymongo/network.py", line 102, in command
    helpers._check_command_response(response_doc, None, allowable_errors)
  File "/home/sreenadh/.local/lib/python2.7/site-packages/pymongo/helpers.py", line 205, in _check_command_response
    raise OperationFailure(msg % errmsg, code, response)
OperationFailure: not authorized on admin to execute command { currentOp: 1, $all: false }

What am trying to do with log4mongo :

I am writing a scrapy spider in which I need the log to be sent to MongoDB. My other mongo connections using MongoClient auth uri works fine. (ie.: client=MongoClient('mongodb://username:password@localhost:27045') ) with auth db as admin that has roles granted accordingly.

I followed the README, but I can't get the Auth part to work, when the MongoDB is with auth disabled, the connection works.

handler = MongoHandler(
level=logging.DEBUG,
host='localhost',
port=27045,
database_name='SPIDER_LOGS',
collection='logs',
username='username_here',
password='password_here',
authentication_db='admin'
)

Versions used:

python : 2.7
mongodb : 3.4.4
pymongo : 3.4.0
@char0n
Copy link
Collaborator

char0n commented May 9, 2017

@oz123 any idea ? I don't see any reason why this should not work.

@sreecodeslayer
Copy link
Author

sreecodeslayer commented May 9, 2017

Hey, I got it to work

When I checked the Pymongo doc, it says we can pass uri in to host.

The host parameter can be a full mongodb URI, in addition to a simple hostname. It can also be a list of hostnames or URIs.

So instead of giving username, password separately, i gave it like this,

handler = MongoHandler(host='mongodb://username:password@localhost:27045')

and everything remains same, and I can confirm I have log data in the collection, so i guess it is better to mention this in the README for others who is using Auth 🙂 👍

@char0n
Copy link
Collaborator

char0n commented May 9, 2017

Will do. Thanks.

I will close this issue after README is updated.

@char0n
Copy link
Collaborator

char0n commented May 25, 2017

Still pending..

@lamter
Copy link

lamter commented Jul 19, 2017

It happended to me and I guess I found the reason.
It happens in MongoHandler._connect meth. For a database need auth, connect.is_locked should be call after auth.But, it adverses.
It will be normal at no-auth situation, but not at auth need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants