Skip to content

Commit 2b15fe4

Browse files
committed
Merge pull request #50 from hokadiri/master
Handling paramiko.ssh_exception.ChannelException when connecting via proxy_host
2 parents b69ab6e + 13e4d09 commit 2b15fe4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pssh/ssh_client.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
monkey.patch_all()
2727
import logging
2828
import paramiko
29+
from paramiko.ssh_exception import ChannelException as channel_exception
2930
import os
3031
from socket import gaierror as sock_gaierror, error as sock_error
3132
from .exceptions import UnknownHostException, AuthenticationException, \
@@ -134,11 +135,16 @@ def _connect_tunnel(self):
134135
self._connect(self.proxy_client, self.proxy_host, self.proxy_port)
135136
logger.info("Connecting via SSH proxy %s:%s -> %s:%s", self.proxy_host,
136137
self.proxy_port, self.host, self.port,)
137-
proxy_channel = self.proxy_client.get_transport().\
138-
open_channel('direct-tcpip', (self.host, self.port,),
139-
('127.0.0.1', 0))
140-
return self._connect(self.client, self.host, self.port, sock=proxy_channel)
141-
138+
try:
139+
proxy_channel = self.proxy_client.get_transport().\
140+
open_channel('direct-tcpip', (self.host, self.port,),
141+
('127.0.0.1', 0))
142+
return self._connect(self.client, self.host, self.port, sock=proxy_channel)
143+
except channel_exception, ex:
144+
error_type = ex.args[1] if len(ex.args) > 1 else ex.args[0]
145+
raise ConnectionErrorException("Error connecting to host '%s:%s' - %s",
146+
self.host, self.port,
147+
str(error_type))
142148
def _connect(self, client, host, port, sock=None, retries=1):
143149
"""Connect to host
144150

0 commit comments

Comments
 (0)