socket.gaierror连接到远程服务器时

时间:2016-06-14 19:11:00

标签: python sockets ssh proxy

我正在尝试连接到远程数据库,如下所示:

with SSHTunnelForwarder(
    ssh_address=('10.160.1.24', 22),
    ssh_username='Administrator',
    ssh_password=ssh_password,
    remote_bind_address=('127.0.0.1', 5432)) as server:
    print("test")

但我遇到了这个错误:

remote_bind_address=('127.0.0.1', 5432)) as server:
  File "/Library/Python/2.7/site-packages/sshtunnel.py", line 879, in __init__
    self._local_interfaces = self._get_local_interfaces()
  File "/Library/Python/2.7/site-packages/sshtunnel.py", line 1378, in _get_local_interfaces
    local_if = socket.gethostbyname_ex(socket.gethostname())[-1]
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

1 个答案:

答案 0 :(得分:0)

问题是因为缺少local_bind_address参数。该方法似乎期望这个参数,即使它是可选的。