0
我是新來的龍捲風和桃子(我使用之前的查詢),我一直當我運行這個方法得到這個錯誤:桃子坪設置
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)`