I'm new to Tornado and Momoko (i was using queries before) , I keep getting this error when I run this method:
psycopg2.OperationalError: could not translate host name \"pg\" to address: No address associated with hostname
i know that the host works because i have made successful connections with queries.
here is how i am setting it up (its a simple checker function to make sure the connection still works):
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)`
答案 0 :(得分:0)
你应该产生未来,然后恢复你的功能,其结果将是可用的
future = momoko.Connection(dsn=self.dsn, ioloop=loop).connect()
yield future
conn = future.result()
或更短的版本:
conn = yield momoko.Connection(dsn=self.dsn, ioloop=loop).connect()