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

Can not connect to mongodb on cloud server #386

Closed
boh5 opened this issue May 5, 2020 · 3 comments · Fixed by #477
Closed

Can not connect to mongodb on cloud server #386

boh5 opened this issue May 5, 2020 · 3 comments · Fixed by #477
Labels
type: bug Something isn't working

Comments

@boh5
Copy link

boh5 commented May 5, 2020

I can connect to mongodb on my cloud server by mongodb compass and navicat, so I am sure that the username, password, host and port is correct, and the firewall configuration is correct.
But when I connect using flask-mongoengine, I get exception:

pymongo.errors.OperationFailure: Authentication failed.

I can connect to my local mongodb without password by flask-mongoengine.
My configration is like below:

MONGODB_HOST = 'xxx.xxx.xxx.xxx'
MONGODB_PORT = 27017
MONGODB_USERNAME = 'username'
MONGODB_PASSWORD = 'p@ssword'  # There is an `@` in my password, and I have tried use `%40` instead of `@` but not work
MONGODB_AUTHENTICATION_SOURCE = 'admin'
MONGODB_DB = 'my_db'

The versions:

mongodb server == 4.2.6
flask-mongoengine == 0.9.5
mongoengine == 0.19.1
pymongo == 3.10.1

Thanks!

Update:
I found that it seems a bug.
If I provid individual settings, flask-mongoengine do not support authentication_source setting, cause the Authentication failed.
If I provid dictionary settings with authentication_source: 'admin' like below, connect to mongodb success.

MONGODB_SETTINGS = {
    'db': 'my_db',
    'host': 'xxx.xxx.xxx.xxx',
    'port': 27017,
    'username': 'username',
    'password': 'p@ssword',
    'authentication_source': 'admin'
    }
This was referenced May 6, 2020
@mromagnoli
Copy link

mromagnoli commented Jun 3, 2020

you saved me! It was happening to me when connecting to my mongo container

@insspb insspb added the type: bug Something isn't working label Jun 8, 2020
@insspb
Copy link
Collaborator

insspb commented Dec 27, 2020

Please take a look at #429, I think changes from there will help.

@insspb
Copy link
Collaborator

insspb commented Jul 9, 2022

Connection/Flask settings documentation updated in #477. Different settings options described. All options except list of dictionaries are deprecated since next version (2.0.0). Please refer to current documentation for more info and settings update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
3 participants