txmongo icon indicating copy to clipboard operation
txmongo copied to clipboard

pymongo.errors.OperationFailure: TxMongo: not authorized for query on foo.test

Open ma-pony opened this issue 2 years ago • 1 comments

When I connect to MongoDB using my username password, it throws an error not authorized, is there a configuration problem?

env:

docker run --name mongo-4.2.0 -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=username -e MONGO_INITDB_ROOT_PASSWORD=password --restart always -d mongo:4.2.0

Platform macOS-13.3.1-arm64-arm-64bit
Python 3.10.8

MongoDB 4.2.0

twisted==21.7.0
txmongo==23.0.0
pymongo==3.13.0 

code:

from twisted.internet import defer, reactor
from txmongo.connection import ConnectionPool


@defer.inlineCallbacks
def example():
    mongodb_uri = "mongodb://username:[email protected]:27017/?authMechanism=DEFAULT"

    mongo = yield ConnectionPool(mongodb_uri)

    foo = mongo.foo  # `foo` database
    test = foo.test  # `test` collection

    # fetch some documents
    docs = yield test.find(limit=10)
    for doc in docs:
        print(doc)


if __name__ == '__main__':
    example().addCallback(lambda ign: reactor.stop())
    example().addErrback(lambda ign: reactor.stop())
    reactor.run()

ma-pony avatar May 11 '23 11:05 ma-pony

image MongoDB 4.0 and later default sha256 mec,txmongo doesn't seem to support this option

ma-pony avatar May 12 '23 06:05 ma-pony