问题是我无法连接到本地主机数据库(5432端口),在此Postgresql上我确实很绿,但我仍然不了解这些数据库及其工作方式。我的连接代码:
import psycopg2
try:
connection = psycopg2.connect(user = "sysadmin",
password = "pynative@#29",
host = "127.0.0.1",
port = "5432",
database = "postgres_db")
cursor = connection.cursor()
# Print PostgreSQL Connection properties
print ( connection.get_dsn_parameters(),"\n")
# Print PostgreSQL version
cursor.execute("SELECT version();")
record = cursor.fetchone()
print("You are connected to - ", record,"\n")
except (Exception, psycopg2.Error) as error :
print ("Error while connecting to PostgreSQL", error)
finally:
#closing database connection.
if(connection):
cursor.close()
connection.close()
print("PostgreSQL connection is closed")
我还在本地主机rooter上做了一些端口转发。
据我所知,我将“ nmap”软件用于正在运行的端口吗?我得到的结果在这里NMAP