Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to authenticate to a remote db host with MongoKit?

I am attempting to connect and authenticate to a remote database host (dotcloud, mongolabs, etc) using MongoKit within Flask. Connecting to the server seems to work fine. However I am unable to authenticate to the database. Presumably this should work:

from mongokit import Connection
connection = Connection(my_remote_host, my_remote_port)
connection.my_database.authenticate(my_admin_user, my_admin_password)

the call to authenticate() returns True, yet subsequent calls to fetch data throw:

OperationFailure: database error: unauthorized db

Anyone know what might be happening here?

like image 481
detour Avatar asked Oct 10 '22 12:10

detour


1 Answers

This is likely due to the current behavior of authenticate() in pymongo. Pymongo doesn't cache authentication credentials between threads, so each thread must authenticate individually. See the note in the pymongo documentation about using authenticate() in a multi-threaded environment.

like image 122
dcrosta Avatar answered Oct 14 '22 02:10

dcrosta