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

when use MONGO_URI, error: Another user is already authenticated #82

Closed
syfun opened this issue Jul 15, 2016 · 10 comments
Closed

when use MONGO_URI, error: Another user is already authenticated #82

syfun opened this issue Jul 15, 2016 · 10 comments
Labels
BUG

Comments

@syfun
Copy link

@syfun syfun commented Jul 15, 2016

I use a cloud mongodb server, version is 3.0.7. But its authMechanism is 'MONGODB-CR', not default 'SCRAM-SHA-1'. So when I used 'MONGODB-CR', occured error 'Another user is already authenticated'. My MONGO_URI:
'mongodb://demo:123456@127.0.0.1:27017/demo?authMechanism=MONGODB-CR'

I read source code, and found the reason,

# flask_pymongo/__init__.py 252-253
if any(auth):
    db.authenticate(username, password)

authenticate not assign mechanism agument, so 'DEFAULT‘ and occured my error.

@lafrech
Copy link

@lafrech lafrech commented Jul 24, 2016

Can you try to apply the following changes?

In URI parsing, add this line:

app.config[key('AUTH_MECHANISM')] = parsed['options'].get('authMechanism', 'DEFAULT')

In URI-less config, add this line:

app.config.setdefault(key('AUTH_MECHANISM'), 'DEFAULT')

Then when calling authenticate:

mechanism = app.config[key('AUTH_MECHANISM')]
db.authenticate(username, password, mechanism=mechanism)

This untested patch could help. If it does not work as is, it may be a hint.

@syfun
Copy link
Author

@syfun syfun commented Jul 25, 2016

@lafrech I used the same solution for this, and thank you for the reply.

@dcrosta
Copy link
Owner

@dcrosta dcrosta commented May 22, 2017

@syfun I know this is a very old bug and it sounds like you've gotten a workaround for this at this point. But I'm trying to revive this project, and I've just recently merged #88, which I think should fix your issue as well. I'll be releasing 0.5.0 soon. When I do, would you be able to test and confirm here whether that works for you?

@dcrosta dcrosta added the BUG label May 22, 2017
@syfun
Copy link
Author

@syfun syfun commented May 22, 2017

@dcrosta Ok for that. This bug is realy old enough. I alreay fixed, but almost forgot that. Sorry for not further communication. I will seriously test after you releasing 0.5.0.

@dcrosta dcrosta closed this in ab0fee2 May 22, 2017
@chattr1n
Copy link

@chattr1n chattr1n commented May 24, 2017

@dcrosta in 0.5.0, I get this error. not sure if it's related to this issue above:

File "/home/someuser/.local/lib/python3.5/site-packages/flask_pymongo/init.py", line 97, in init
self.init_app(app, config_prefix)
File "/home/someuser/.local/lib/python3.5/site-packages/flask_pymongo/init.py", line 278, in init_app
auth_mechanism = app.config[key('AUTH_MECHANISM')]
KeyError: 'MONGO_AUTH_MECHANISM'

I went back to 0.4.1 and it works.

@syfun
Copy link
Author

@syfun syfun commented May 24, 2017

@chattr1n @dcrosta I also encounter this error. I found the reason in the code.
When user not define MONGO_URI, AUTH_MECHANISM had no default value.

@dcrosta
Copy link
Owner

@dcrosta dcrosta commented May 24, 2017

I believe that will be fixed by #93, which I'll be releasing shortly as 0.5.1.

@dcrosta
Copy link
Owner

@dcrosta dcrosta commented May 24, 2017

0.5.1 is now in PyPI -- please upgrade and let me know if that fixes it. If not, we can dig in deeper here.

@syfun
Copy link
Author

@syfun syfun commented May 25, 2017

@dcrosta That's OK for 0.5.1.

@dcrosta
Copy link
Owner

@dcrosta dcrosta commented May 25, 2017

Great, thanks for following up!

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

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.