Skip to content

Commit 9f20c10

Browse files
author
Hussein Kadiri
committed
handling paramiko.ssh_exception.ChannelException
1 parent b69ab6e commit 9f20c10

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pssh/ssh_client.py

Lines changed: 10 additions & 4 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 import ssh_exception.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))
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))
140142
return self._connect(self.client, self.host, self.port, sock=proxy_channel)
141-
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)