Thomas Browne
Thomas Browne

Reputation: 24888

Does Motor for python tornado accept ssl connections to Mongodb?

I don't see any documentation and I am unable to get it working.

I am performing the analogous actions to pymongo:

import motor
cl = motor.MotorClient("192.168.1.5", ssl = True)
cl.admin.authenticate("someuser", "somepassword")
db = cl.bb     #this contains data already
from tornado import gen
import tornado.ioloop

@gen.coroutine
def do_find_one():
    document = yield db.bbticks.find_one({})
    print(document)

tornado.ioloop.IOLoop.instance().start()
IOLoop.current().run_sync(do_find_one)

In [1]: %run motortest.py

(blocks, with no prompt coming back)

So from this I get no results whatsoever, though I should get a record as the database is definitely populated:

import pymongo
cl = pymongo.MongoClient("192.168.1.5", ssl = True)
cl.admin.authenticate("someuser", "somepassword")
db = cl.bb

document = db.bbticks.find_one({})
print(document)

In [3]: %run mongotest.py
{'open': 11650.0, 'close': 11650.0, 'value': 11650.0, 'low': 11650.0, 'numevents': 56, 'high': 11650.0, '_id': ObjectId('5444172e56ac847a43260b32'), 'source': 'HIST', 'time': datetime.datetime(2014, 7, 29, 13, 42), 'ticker': 'IHN+1M CMPL Curncy'}

EDIT for A. Jesse Jiryu Davis answer

second last line commented out and "tornado.ioloop." prepended to final line

import motor
cl = motor.MotorClient("192.168.1.5", ssl = True)
cl.admin.authenticate("someuser", "somepassword")
db = cl.bb
from tornado import gen
import tornado.ioloop

@gen.coroutine
def do_find_one():
    document = yield db.bbticks.find_one({})
    print(document)

#tornado.ioloop.IOLoop.instance().start()
tornado.ioloop.IOLoop.current().run_sync(do_find_one)

In [3]: %run motortest.py
{'low': 11650.0, 'ticker': 'IHN+1M CMPL Curncy', '_id': ObjectId('5444172e56ac847a43260b32'), 'value': 11650.0, 'time': datetime.datetime(2014, 7, 29, 13, 42), 'numevents': 56, 'high': 11650.0, 'close': 11650.0, 'source': 'HIST', 'open': 11650.0}

Upvotes: 1

Views: 445

Answers (1)

A. Jesse Jiryu Davis
A. Jesse Jiryu Davis

Reputation: 24007

Yes, Motor does SSL since version 0.2. Your problem is the call to IOLoop.instance().start(). The IOLoop runs forever, and your script never reaches the line with "run_sync". Remove the line with "start" and your should get the results you expect.

Upvotes: 2

Related Questions