我是Tornado和Momoko的新手(我之前使用的是查询),当我运行这个方法时,我一直收到这个错误:
psycopg2.OperationalError: could not translate host name \"pg\" to address: No address associated with hostname
我知道主机可以工作,因为我已经成功地与查询建立了连接。
以下是我如何设置它(这是一个简单的检查函数,以确保连接仍然有效):
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)`https://stackoverflow.com/questions/38315147
复制相似问题