我正在尝试查询PostgreSQL数据库以检索我的表。我一直陷入 Psycopg2
的错误import psycopg2
try:
conn = pyscopg2.connect(database='wildlife', user='postgres', password='P@$$w0rd', host='localhost' port='5432')
print "successfully connected to database"
except:
print "connection Failure"
cur = conn.cursor()
cur.execute("SELECT ID,NAME,LIVES,WEIGHT,LEGS,CLASS,NUMBER,CATEGORY FROM CAGE";)
rows = cur.fetchall()
for row in rows:
print "ID = ", row[0]
print "NAME = ", row[1]
print "LIVES = ", row[2], "\n"
conn.close()
和错误
Error executing SQL statement. ERROR: syntax error at or near "psycopg2"
位置:8-连接:阶段1:275ms
答案 0 :(得分:0)
此行包含一个错字:
conn = pyscopg2.connect(...
应该是:
conn = psycopg2.connect(
“ y”和“ s”已换位。