Mongo/Pymongo Sharded Auth Problem

Showing 1-3 of 3 messages
Mongo/Pymongo Sharded Auth Problem Dennis Crenshaw 10/18/12 10:04 AM
I'm running Mongo 2.2.0, sharded and replicated, and I'm having a bit of weird behavior using python (pymongo 2.1.1).

Things to note:
   Users with correct privileges have been created on each database I am attempting to access (our user, USER, is a regular user)
   The following are connecting via a mongo router
   MONGO_URI is an env variable set earlier in deployment: $MONGO_URI = "mongodb://USER:PASSWORD@localhost:27017/DB"

I can auth, read and write just fine through the mongo shell, I can also fire up a python session and the following works just fine:

>>> import pymongo
>>> import os
>>> c = pymongo.Connection(os.environ['MONGODB_URI'])
>>> c.DB.COLL.insert(dict(a=2))
>>> list(c.DB.COLL.find())

But when I use safe=True on insert:

>>> import pymongo
>>> import os
>>> c = pymongo.Connection(os.environ['MONGODB_URI'])
>>> c.DB.COLL.insert(dict(a=2), safe=True)

I get this error:

Traceback (most recent call last):
  File "bin/create", line 21, in <module>
    db.DB.insert(THING, safe=True)
  File "local/lib/python2.7/site-packages/pymongo/collection.py", line 312, in insert
    continue_on_error, self.__uuid_subtype), safe)
  File "local/lib/python2.7/site-packages/pymongo/connection.py", line 822, in _send_message
    return self.__check_response_to_last_error(response)
  File "local/lib/python2.7/site-packages/pymongo/connection.py", line 759, in __check_response_to_last_error
    helpers._check_command_response(error, self.disconnect)
  File "local/lib/python2.7/site-packages/pymongo/helpers.py", line 128, in _check_command_response
    raise OperationFailure(msg % response["errmsg"])
pymongo.errors.OperationFailure: unauthorized

Am I calling something the wrong way, or might there be a bug with auth and safe somewhere? I'm inclined to believe in my own error first, but I get correct behavior if I leave safe off of safe in the insert statement.
Re: [mongodb-user] Mongo/Pymongo Sharded Auth Problem Bernie Hackett 10/18/12 11:25 AM
There was a change in MongoDB 2.2.0 that broke getLastError when using
authentication in PyMongo. PyMongo 2.3 fixes this issue. The ticket is
here if you're curious:

https://jira.mongodb.org/browse/PYTHON-371

Upgrading to PyMongo 2.3 will fix this problem for you.
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
Re: [mongodb-user] Mongo/Pymongo Sharded Auth Problem Dennis Crenshaw 10/22/12 6:52 AM
That was it, thanks!