PyMongo Authentication

84 views
Skip to first unread message

ja...@blendlabs.com

unread,
Jan 18, 2017, 8:47:02 AM1/18/17
to mongodb-user
Does anyone know how to auth with pymongo w/o username and password?

>>> client['localhost'].authenticate('','', mechanism='MONGODB-CR')

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line 1018, in authenticate

    connect=True)

  File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 444, in _cache_credentials

    sock_info.authenticate(credentials)

  File "/usr/local/lib/python2.7/dist-packages/pymongo/pool.py", line 343, in authenticate

    auth.authenticate(credentials, self)

  File "/usr/local/lib/python2.7/dist-packages/pymongo/auth.py", line 464, in authenticate

    auth_func(credentials, sock_info)

  File "/usr/local/lib/python2.7/dist-packages/pymongo/auth.py", line 432, in _authenticate_mongo_cr

    key = _auth_key(nonce, username, password)

  File "/usr/local/lib/python2.7/dist-packages/pymongo/auth.py", line 266, in _auth_key

    digest = _password_digest(username, password)

  File "/usr/local/lib/python2.7/dist-packages/pymongo/auth.py", line 252, in _password_digest

    raise ValueError("password can't be empty")

ValueError: password can't be empty

>>> client['localhost'].authenticate('',None, mechanism='MONGODB-CR')

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line 1013, in authenticate

    validated_options)

  File "/usr/local/lib/python2.7/dist-packages/pymongo/auth.py", line 77, in _build_credentials_tuple

    raise ConfigurationError("A password is required.")

pymongo.errors.ConfigurationError: A password is required.

Andrew Erlichson

unread,
Jan 18, 2017, 10:28:27 AM1/18/17
to mongodb-user
If you want to connect to a database with no auth enabled, you call call MongoClient()

Instructions are here:


Note that you should always secure MongoDB for a production deployment, including running it behind a firewall and turning authentication on.  Here is a full security checklist.
Reply all
Reply to author
Forward
0 new messages