我想从不同的服务器使用python连接到postgresql数据库。
我对此表示不满:
conn_string = "host=192.168.1.1 dbname='"+db7+"' user='user' password='"+pw7+"'"
conn = psycopg2.connect(conn_string)
cursor = conn.cursor()
但是我收到了错误:
conn = psycopg2.connect(conn_string)
File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect
connection_factory=connection_factory, async=async)
psycopg2.OperationalError: FATAL: database "database" does not exist
答案 0 :(得分:1)
删除语法中不必要的引号。
遵循这个结构。
conn = psycopg2.connect(host = "localhost",database="ur_database_name", user="db_user", password="your_password")
实施例
conn = psycopg2.connect(host = "localhost",database="studentesdb", user="postgres", password="admin")