Re: [mongodb-user] Mongo/Pymongo Sharded Auth Problem

37 views
Skip to first unread message

Bernie Hackett

unread,
Oct 18, 2012, 2:24:59 PM10/18/12
to mongod...@googlegroups.com
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.

On Thu, Oct 18, 2012 at 10:04 AM, Dennis Crenshaw <crens...@gmail.com> wrote:
> 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.
>
> --
> 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
Reply all
Reply to author
Forward
0 new messages