我正在尝试使用 db。所以我使用以下连接信息连接到 PostgreSQL 数据库。我正在使用 Jupyter 笔记本。
from sqlalchemy import create_engine
POSTGRES_DIALECT = 'postgresql'
POSTGRES_SERVER = 'server'
POSTGRES_DBNAME = 'db'
POSTGRES_SCHEMA = 'public'
POSTGRES_USERNAME = 'user'
POSTGRES_PASSWORD = 'password'
postgres_str = ('{dialect}://{username}:{password}@{server}/{dbname}'.format(
dialect=POSTGRES_DIALECT,
server=POSTGRES_SERVER,
dbname=POSTGRES_DBNAME,
username=POSTGRES_USERNAME,
password=POSTGRES_PASSWORD
))
# Create the connection
cnx = create_engine(postgres_str)
agreements_df = pd.read_sql_query('''SELECT * from db''', cnx)
agreements_df.head()
有错误:
OperationalError: (psycopg2.OperationalError) could not translate host name "server" to address: nodename nor servname provided, or not known