简体   繁体   English

Python 3.6 - Sanic Motorengine

[英]Python 3.6 - Sanic Motorengine

I am trying to setup the new Sanic web framework (which is promised to be extremely fast) with motorengine in order to achieve 100% async. 我试图建立新的Sanic与Web框架(这是承诺是非常快的) motorengine以达到100%异步。

My setup so far: 到目前为止我的设置:

app = Sanic(__name__)

@app.listener('after_server_start')
async def setup_dbconn(app, loop):
    connect("database_name", username="user", password="pass", host="192.168.1.200", port=27017, io_loop=asyncio.get_event_loop())

Unfortunately I get: 不幸的是我得到:

motorengine.connection.ConnectionError: Cannot connect to database default :
Unknown option username

Why does this crash? 为什么会崩溃?

The specific problem you encounter is not about Sanic but has to do with motorengine . 您遇到的具体问题不是Sanic而是与motorengine

Use the database URI to connect: 使用数据库URI连接:

motorengine.connect(
    db=name, 
    alias=alias, 
    host="mongodb://username:password@localhost:port", 
    io_loop=tornado.ioloop.IOLoop.instance()
)     

The solution came from this ticket: https://github.com/heynemann/motorengine/issues/82 . 解决方案来自这张票: https//github.com/heynemann/motorengine/issues/82


PS: For Sanic >= 0.4.0 you should consider using sanic-motor extension! PS:对于Sanic> = 0.4.0,你应该考虑使用sanic-motor扩展!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM