我有一个脚本:
import psycopg2
from sshtunnel import SSHTunnelForwarder
with SSHTunnelForwarder(
('3.120.198.220', 22),
ssh_password='MYPASSWORD',
ssh_username='MYUSER',
ssh_pkey='MYPATH',
remote_bind_address=('192.168.122.61', 5432)) as server:
connection = psycopg2.connect(database='MYDB',user='MYUSER',password='MYPASS',host='192.168.122.61')
cursor = connection.cursor()
和我有的输出:
psycopg2.OperationalError: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "192.168.122.61" and accepting
TCP/IP connections on port 5432?
我检查了我的 postgresql.conf,所以它可以监听所有内容:
<块引用>listen_addresses = '*'
还有我的 pg_hba.conf:
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
host all all 127.0.0.1/32 scram-sha-256
host all all 192.168.122.61/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all scram-sha-256
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
有什么想法吗?