cant get connexion using MongoTor

Posted by Abdelouahab Pp on Stack Overflow See other posts from Stack Overflow or by Abdelouahab Pp
Published on 2012-11-07T10:29:39Z Indexed on 2012/11/08 11:02 UTC
Read the original article Hit count: 368

Filed under:
|
|

i was trying to change my code to make it asynchronous using MongoTor

here is my simple code:

class BaseHandler(tornado.web.RequestHandler):
    @property 
    def db(self):
        if not hasattr(self,"_db"):
            _db = Database.connect('localhost:27017', 'essog')
            return _db
    @property
    def fs(self):
        if not hasattr(BaseHandler,"_fs"):
            _fs = gridfs.GridFS(self.db)
            return _fs


class LoginHandler(BaseHandler):
    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        email = self.get_argument("email")
        password = self.get_argument("pass1")
        try:
            search = yield tornado.gen.Task(self.db.users.find, {"prs.mail":email})
            ....

i got this error:

Traceback (most recent call last):
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\web.py", line 1043, in _stack_context_handle_exception
raise_exc_info((type, value, traceback))
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\web.py", line 1162, in wrapper
return method(self, *args, **kwargs)
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\gen.py", line 122, in wrapper
runner.run()
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\gen.py", line 365, in run
yielded = self.gen.send(next)
File "G:\Mon projet\essog\handlers.py", line 92, in post
search = yield tornado.gen.Task(self.db.users.find, {"prs.mail":email})
File "G:\Mon projet\essog\handlers.py", line 62, in db
_db = Database.connect('localhost:27017', 'essog')
File "build\bdist.win-amd64\egg\mongotor\database.py", line 131, in connect
database.init(addresses, dbname, read_preference, **kwargs)
File "build\bdist.win-amd64\egg\mongotor\database.py", line 62, in init
ioloop_is_running = IOLoop.instance().running()
 AttributeError: 'SelectIOLoop' object has no attribute 'running'
 ERROR:tornado.access:500 POST /login (::1) 3.00ms

and, excuse me for this other question, but how do i make distinct in this case?

here is what worked in blocking mode:

search = self.db.users.find({"prs.mail":email}).distinct("prs.mail")[0]

Update:

it seems that this error happenes when there is no Tornado running! it's the same error raised when using only the module in console.

test = Database.connect("localhost:27017", "essog") --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in () ----> 1 test = Database.connect("localhost:27017", "essog")

C:\Python27\lib\site-packages\mongotor-0.0.10-py2.7.egg\mongotor\database.pyc in connect(cls, addresses, dbname, read_preference, **kwargs) 131 132 database = Database() --> 133 database.init(addresses, dbname, read_preference, **kwargs) 134 135 return database

C:\Python27\lib\site-packages\mongotor-0.0.10-py2.7.egg\mongotor\database.pyc in init(self, addresses, dbname, read_preference, **kwargs) 60 self._nodes.append(node) 61 ---> 62 ioloop_is_running = IOLoop.instance().running() 63 self._config_nodes(callback=partial(self._on_config_node, ioloop_is_running)) 64

AttributeError: 'SelectIOLoop' object has no attribute 'running'

© Stack Overflow or respective owner

Related posts about mongodb

Related posts about asynchronous