无法使用 psycopg 连接到 Azure postgres。找不到您尝试的服务器名称

Can't connect to Azure postgres with psycopg. The server name you tried cannot be found

我想通过 psycopg2 从外部连接到 Azure postgresql。我创建了一个带有 postgresql 数据库的服务器。 问题是,当我尝试创建连接时,出现错误说 'psycopg2.OperationalError: FATAL: The server name you tried cannot be found. Please use the correct name and retry. Please check your server name lfsserverlv.'

import psycopg2

conn = psycopg2.connect(
    host='lfsserverlv.database.windows.net',
    dbname='lfsdb',
    user='adminlfs@lfsserverlv',
    password='some_password',
    sslmode='require'
)

服务器名称在下面的截图中(抱歉里面有俄语) 关于与 Azure 的连接,应该还有其他我可能不知道的东西。 任何帮助将不胜感激

确保您传递了正确的服务器名称。

获取连接到 Azure Database for PostgreSQL 所需的连接信息。您需要完全限定的服务器名称和登录凭据。

  1. 登录 Azure 门户
  2. 从 Azure 门户的 left-hand 菜单中,单击 所有资源 ,然后搜索您创建的服务器(例如 chepra).
  3. 单击服务器名称。
  4. 在服务器的概览面板中,记下服务器名称服务器管理员登录名。如果您忘记了密码,您也可以从此面板重设密码。

通过使用上述连接信息,我可以使用 python 连接 Azure Database for PostgreSQL,如下所示:

详情请参考“Connect Azure Database for PostgreSQL using Python”。

希望对您有所帮助。