首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Momoko Ping设置

Momoko Ping设置
EN

Stack Overflow用户
提问于 2016-07-12 03:55:31
回答 0查看 112关注 0票数 0

我是Tornado和Momoko的新手(我之前使用的是查询),当我运行这个方法时,我一直收到这个错误:

psycopg2.OperationalError: could not translate host name \"pg\" to address: No address associated with hostname

我知道主机可以工作,因为我已经成功地与查询建立了连接。

以下是我如何设置它(这是一个简单的检查函数,以确保连接仍然有效):

代码语言:javascript
复制
def __init__(self, event, frequency, params):
    super().__init__(event, frequency, params)
    # uri of PGDB
    self.dsn ='dbname=%s user=%s password=%s host=%s port=%s' % (configuration["postgre"][0]["dbName"],
                                                                 configuration["postgre"][0]["userName"],
                                                                 configuration["postgre"][0]["password"],
                                                                 configuration["postgre"][0]["host"],
                                                                 configuration["postgre"][0]["port"])
    logging.info(self.dsn)
    # creates actual link to DB
    self.Pg_Loop = IOLoop

    self.host = configuration["postgre"][0]["host"]

@gen.coroutine
def check(self):
    try:
        loop = self.Pg_Loop
        pool = momoko.Connection(dsn=self.dsn, ioloop=loop)
        future = yield pool.connect()
        yield future.result()
        data = {'host': self.host, 'status': events.STATUS_OK}
    except (PartiallyConnectedError, PoolError, InternalError, DatabaseError, OperationalError):
        data = {'host': self.host, 'status': events.STATUS_FAIL, 'error': traceback.format_exc()}
    self.save(data)`
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38315147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档