Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
OperationFailure on insert
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jorge Puente Sarrín  
View profile  
 More options Sep 6 2012, 3:45 pm
From: Jorge Puente Sarrín <puentesar...@gmail.com>
Date: Thu, 6 Sep 2012 14:44:33 -0500
Local: Thurs, Sep 6 2012 3:44 pm
Subject: [pymongo-motor] OperationFailure on insert

Hi, I'm following the Motor
examples<http://emptysquare.net/motor/pymongo/api/motor/examples.html#using-to...>,
but my code raise a exception when insert a document using yield operator
and motor Op/Task.

Here my code:

class ContentHandler(MotorSampleHandler):

    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        title = self.get_argument('title')
        slug = stringhelper.get_slug(title)
        content = {'title': title,
            'content': self.get_argument('content'),
            'slug': slug,
            'date': datetime.datetime.now()}
        *yield motor.Op(self.db.contents.insert, content)*
        self.redirect('/%s' % slug)

This is the traceback:

    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line
1000, in _stack_context_handle_exception
        raise_exc_info((type, value, traceback))
      File
"/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line
256, in _nested
        yield vars
      File
"/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line
226, in wrapped
        callback(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line
382, in inner
        self.set_result(key, result)
      File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line
315, in set_result
        self.run()
      File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line
343, in run
        yielded = self.gen.throw(*exc_info)
*      File
"/home/puentesarrin/projects/motor-sample/motor-sample/handlers.py", line
111, in post*
*        yield motor.Op(self.db.contents.insert, content)*
      File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line
335, in run
        next = self.yield_point.get_result()
      File "/usr/local/lib/python2.7/dist-packages/motor/__init__.py", line
1365, in get_result
        raise error
    OperationFailure: need to login

I think that it's not about instance PyMongo Connection because, all of
queries (find/find_one) results is ok.

Python version: 2.7.3
Tornado version: 2.3
PyMongo version: 2.2

--
Atte.
Jorge Puente Sarrín.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jorge Puente Sarrín  
View profile  
 More options Sep 6 2012, 3:57 pm
From: Jorge Puente Sarrín <puentesar...@gmail.com>
Date: Thu, 6 Sep 2012 14:56:57 -0500
Local: Thurs, Sep 6 2012 3:56 pm
Subject: Re: [pymongo-motor] OperationFailure on insert

I have reviewed the DB and the document is inserted correctly, but I don't
understand why raise this exception.

Regards.

2012/9/6 Jorge Puente Sarrín <puentesar...@gmail.com>

--
Atte.
Jorge Puente Sarrín.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
A. Jesse Jiryu Davis  
View profile  
 More options Sep 6 2012, 5:28 pm
From: "A. Jesse Jiryu Davis" <je...@10gen.com>
Date: Thu, 6 Sep 2012 14:28:50 -0700 (PDT)
Local: Thurs, Sep 6 2012 5:28 pm
Subject: Re: [pymongo-motor] OperationFailure on insert

In that case it seems that you are, perhaps, logged in as a read-only user,
and you're mistaken that your document was correctly inserted? Try this:

import datetime
from tornado.ioloop import IOLoop
from tornado import gen
import motor

db = motor.MotorConnection().open_sync().my_database
loop = IOLoop.instance()

@gen.engine
def go():
    print 'dropping my_collection'
    yield motor.Op(db.drop_collection, 'my_collection')
    count = yield motor.Op(db.my_collection.count)
    print 'count is', count

    content = {'title': 'title',
               'content': 'content',
               'slug': 'slug',
               'date': datetime.datetime.now()}
    yield motor.Op(db.my_collection.insert, content)
    count = yield motor.Op(db.my_collection.count)
    print 'count is', count
    loop.stop()

go()
loop.start()

Replace "my_database" with the database you're using, and run this script,
please. Be aware that this script drops a collection called "my_collection."


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "[pymongo-motor] OperationFailure on insert" by Jorge Puente Sarrín
Jorge Puente Sarrín  
View profile  
 More options Sep 6 2012, 6:02 pm
From: Jorge Puente Sarrín <puentesar...@gmail.com>
Date: Thu, 6 Sep 2012 17:01:45 -0500
Local: Thurs, Sep 6 2012 6:01 pm
Subject: Re: [mongodb-user] Re: [pymongo-motor] OperationFailure on insert

Hi Jesse,

I have tried to run your snippet and I think that the problem is
Connection, because for create it, I'm using a Uri such as:

db = motor.MotorConnection('mongodb://user:p...@xxxxx.mongolab.com:
xxxxx/dbname?safe=true').open_sync().dbname

This is the traceback,

ERROR:root:Exception in callback
<tornado.stack_context._StackContextWrapper object at 0x7fc5af09bd08>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py", line
421, in _run_callback
    callback()
  File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py",
line 229, in wrapped
    callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 382,
in inner
    self.set_result(key, result)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 315,
in set_result
    self.run()
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 343,
in run
    yielded = self.gen.throw(*exc_info)
  File "<stdin>", line 4, in go
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 335,
in run
    next = self.yield_point.get_result()
  File "/usr/local/lib/python2.7/dist-packages/motor/__init__.py", line
1365, in get_result
    raise error
OperationFailure: db assertion failure, assertion: 'unauthorized
db:my_database ns:my_database lock type:1 client:190.41.238.178',
assertionCode: 10057

Does PyMongo invoke to authenticate method when a uri have a user/password?
Or Does PyMongo ignored it, when uri have a db name?

2012/9/6 A. Jesse Jiryu Davis <je...@10gen.com>

--
Atte.
Jorge Puente Sarrín.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
A. Jesse Jiryu Davis  
View profile  
 More options Sep 6 2012, 6:08 pm
From: "A. Jesse Jiryu Davis" <je...@10gen.com>
Date: Thu, 6 Sep 2012 15:08:56 -0700 (PDT)
Local: Thurs, Sep 6 2012 6:08 pm
Subject: Re: [mongodb-user] Re: [pymongo-motor] OperationFailure on insert

I see. Does that work with a regular PyMongo Connection?:

db = pymongo.Connection('mongodb://user:pass@xxxxx.
mongolab.com:xxxxx/dbname?safe=true').dbname
db.my_collection.insert({}, safe=True)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jorge Puente Sarrín  
View profile  
 More options Sep 6 2012, 6:24 pm
From: Jorge Puente Sarrín <puentesar...@gmail.com>
Date: Thu, 6 Sep 2012 17:23:23 -0500
Local: Thurs, Sep 6 2012 6:23 pm
Subject: Re: [mongodb-user] Re: [pymongo-motor] OperationFailure on insert

No, that's not working.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line
306, in insert
    continue_on_error, self.__uuid_subtype), safe)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/connection.py", line
745, in _send_message
    rv = self.__check_response_to_last_error(response)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/connection.py", line
681, in __check_response_to_last_error
    helpers._check_command_response(error, self.disconnect)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/helpers.py", line
129, in _check_command_response
    raise OperationFailure(msg % response["errmsg"])
pymongo.errors.OperationFailure: need to login

Then, what's the best way for work with a MongoDB Uri and authenticate?

def connect(user, pass):
     yield motor.Op(db.authenticate, user, pass)

2012/9/6 A. Jesse Jiryu Davis <je...@10gen.com>

--
Atte.
Jorge Puente Sarrín.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bernie Hackett  
View profile  
 More options Sep 6 2012, 7:26 pm
From: Bernie Hackett <ber...@10gen.com>
Date: Thu, 6 Sep 2012 16:25:55 -0700
Local: Thurs, Sep 6 2012 7:25 pm
Subject: Re: [mongodb-user] Re: [pymongo-motor] OperationFailure on insert
Are you sure you're using the correct credentials? I can't reproduce
the problem:

>>> c = pymongo.Connection('mongodb://user:pass@localhost:27017/foo')
>>> c.foo.bar.insert({'foo': ' bar'}, safe=True)

ObjectId('50492fdb430ee6c7d3c1435f')
>>> c.foo.bar.find_one()

{u'_id': ObjectId('50492fdb430ee6c7d3c1435f'), u'foo': u' bar'}

# Calling logout then find_one here to show that we were actually authenticated.

>>> c.foo.logout()
>>> c.foo.bar.find_one()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pymongo/collection.py", line 516, in find_one
    for result in self.find(spec_or_id, *args, **kwargs).limit(-1):
  File "pymongo/cursor.py", line 778, in next
    if len(self.__data) or self._refresh():
  File "pymongo/cursor.py", line 729, in _refresh
    self.__uuid_subtype))
  File "pymongo/cursor.py", line 686, in __send_message
    self.__uuid_subtype)
  File "pymongo/helpers.py", line 104, in _unpack_response
    error_object["$err"])
pymongo.errors.OperationFailure: database error: unauthorized db:foo
ns:foo.bar lock type:0 client:127.0.0.1

On Thu, Sep 6, 2012 at 3:23 PM, Jorge Puente Sarrín


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jorge Puente Sarrín  
View profile  
 More options Sep 6 2012, 7:41 pm
From: Jorge Puente Sarrín <puentesar...@gmail.com>
Date: Thu, 6 Sep 2012 18:40:09 -0500
Local: Thurs, Sep 6 2012 7:40 pm
Subject: Re: [mongodb-user] Re: [pymongo-motor] OperationFailure on insert

Hi Bernie/Jesse,

I'm sure, I'm using MongoDB version 2.2 on MongoLab, Can I send you a
private message with URI?

Traceback:

>>> c.db.bar.insert({'foo': ' bar'}, safe=True)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line
306, in insert
    continue_on_error, self.__uuid_subtype), safe)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/connection.py", line
745, in _send_message
    rv = self.__check_response_to_last_error(response)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/connection.py", line
681, in __check_response_to_last_error
    helpers._check_command_response(error, self.disconnect)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/helpers.py", line
129, in _check_command_response
    raise OperationFailure(msg % response["errmsg"])
pymongo.errors.OperationFailure: need to login
>>> c.db.bar.find_one()

{u'_id': ObjectId('504932f87fffaf3e21aee2da'), u'foo': u' bar'}
>>> c.db.logout()
>>> c.db.bar.find_one()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line
514, in find_one
    for result in self.find(spec_or_id, *args, **kwargs).limit(-1):
  File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
749, in next
    if len(self.__data) or self._refresh():
  File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
700, in _refresh
    self.__uuid_subtype))
  File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
657, in __send_message
    self.__tz_aware)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/helpers.py", line
102, in _unpack_response
    error_object["$err"])
pymongo.errors.OperationFailure: database error: unauthorized db:db
ns:db.bar lock type:0 client:190.41.238.178

Regards.

2012/9/6 Bernie Hackett <ber...@10gen.com>

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bernie Hackett  
View profile  
 More options Sep 6 2012, 7:55 pm
From: Bernie Hackett <ber...@10gen.com>
Date: Thu, 6 Sep 2012 16:55:38 -0700
Local: Thurs, Sep 6 2012 7:55 pm
Subject: Re: [mongodb-user] Re: [pymongo-motor] OperationFailure on insert
Ah, I think I understand your problem then. You're hitting this issue
which is fixed in PyMongo 2.3:

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

You may need to pull the latest source for motor to get that change.

On Thu, Sep 6, 2012 at 4:40 PM, Jorge Puente Sarrín

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jorge Puente Sarrín  
View profile  
 More options Sep 6 2012, 10:45 pm
From: Jorge Puente Sarrín <puentesar...@gmail.com>
Date: Thu, 6 Sep 2012 21:44:33 -0500
Local: Thurs, Sep 6 2012 10:44 pm
Subject: Re: [mongodb-user] Re: [pymongo-motor] OperationFailure on insert

Bernie/Jesse thanks a lot, problem is solved.

2012/9/6 Bernie Hackett <ber...@10gen.com>

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
A. Jesse Jiryu Davis  
View profile  
 More options Sep 7 2012, 10:51 am
From: "A. Jesse Jiryu Davis" <je...@10gen.com>
Date: Fri, 7 Sep 2012 07:51:54 -0700 (PDT)
Local: Fri, Sep 7 2012 10:51 am
Subject: Re: [mongodb-user] Re: [pymongo-motor] OperationFailure on insert

Thanks Bernie, I hadn't thought of that. MongoDB 2.2 slightly changed how
safe writes work with authentication, and Motor didn't catch up with that
change until this commit last week:

https://github.com/ajdavis/mongo-python-driver/commit/71fb9eb3c69b6a4...

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »