[paramiko] Testing an exception

Todd Whiteman toddw at activestate.com
Tue Aug 7 18:32:38 PDT 2007


Hi Jay,

Yes, after looking at the code, a timeout is a case that generates the 
exception you describe. The timeout works like by reading the first line 
from the server (waiting up to 15 seconds by default) and then every 
subsequent banner line must be received within 2 seconds, otherwise you 
get that exception. The relevant code is below:


     def _check_banner(self):
         # this is slow, but we only have to do it once
         for i in range(5):
             # give them 15 seconds for the first line, then just 2 seconds
             # each additional line.  (some sites have very high latency.)
             if i == 0:
                 timeout = self.banner_timeout
             else:
                 timeout = 2
             try:
                 buf = self.packetizer.readline(timeout)
             except Exception, x:
                 raise SSHException('Error reading SSH protocol banner' 
+ str(x))
             if buf[:4] == 'SSH-':
                 break


Cheers,
Todd

jay wrote:
> Thanks Todd.  Its interesting that I was connected to an ssh server on 
> port 22.  Nothing non standard about that.  Could this also be a timeout 
> related exception?  If the remote server is slow to respond?
> 
> Jay
> 
> On 8/7/07, *Todd Whiteman* <toddw at activestate.com 
> <mailto:toddw at activestate.com>> wrote:
> 
>     Hi Jay,
> 
>     You get this exception from connecting to a remote machine on a non-ssh
>     port, so when Paramiko tries to read in the relevant SSH information, it
>     fails and raises the SSHException you received.
> 
>     A simple repro example is to try and connect to the ftp port (port 21)
>     instead of the SSH port (port 22).
> 
>     Cheers,
>     Todd
> 
>     jay wrote:
>      > Hello,
>      >
>      > Like to start off saying paramiko is fantastic and has been a
>     huge time
>      > saver for me at work.  Thanks for the hard work!
>      >
>      > I got the following traceback and am unsure what the problem is.
>      >
>      > Traceback (most recent call last):
>      >   File "ATM.py", line 115, in <module>
>      >     t.connect(username=sftpRemoteUser, password=sftpRemotePassword)
>      >   File
>      >
>     "/usr/local/python251/lib/python2.5/site-packages/paramiko/transport.py",
>      > line 931, in connect
>      >     self.start_client()
>      >   File
>      >
>     "/usr/local/python251/lib/python2.5/site-packages/paramiko/transport.py",
>      > line 398, in start_client
>      >     raise e
>      > SSHException: Error reading SSH protocol banner
>      >
>      > I thought my code would catch all exceptions, but apparently
>     not.  This
>      > particular problem showed up inside this
>      >
>      > try:
>      > except Exception, e:
>      >
>      > So, I would like to try and duplicate it, but I'm not even sure
>     what the
>      > problem was.  Any suggestions on how to duplicate this problem
>     and make
>      > sure the code catches it?  Thanks
>      >
>      >  Jay
>      >
>      >
>      >
>     ------------------------------------------------------------------------
> 
>      >
>      > _______________________________________________
>      > paramiko mailing list
>      > paramiko at lag.net <mailto:paramiko at lag.net>
>      > http://mail.lag.net/mailman/listinfo/paramiko
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> paramiko mailing list
> paramiko at lag.net
> http://mail.lag.net/mailman/listinfo/paramiko




More information about the paramiko mailing list