python - psycopg2.OperationalError:无法连接到服务器:连接超时
问题描述
我有一个脚本:
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,所以它听所有的:
听地址 = '*'
还有我的 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
有任何想法吗?
解决方案
推荐阅读
- javascript - 如果子句出现故障,NodeJS Schema 虚函数
- ios - HorizontalCollectionView 内容宽度和间距
- wordpress - 添加要在自定义帖子类型上显示的自定义模板文件
- apache-kafka - Kafka 跟踪消费者进度
- microservices - 使用 API-Gateway 时如何处理原始 API
- python - 把文件变成字典
- ms-access - 2010 年访问报告,与输入的搜索条件部分匹配
- html - 在同一选项卡中打开来自两个网站的链接
- c++ - 将泛型值复制到无符号字符数组并在 C++ 中复制回来
- sql-server - 未记录的 SmoScriptOption:ScriptForAlter 和 ScriptForCreateDrop