ssh keepalive

  • Follow


I have a problem with a ssh connection in python

I get the error

'NoneType' object has no attribute 'exec_command'

I am thinking that maybe the ssh connection is timeing out.

Since I have no control over the configuration of the ssh server(which
is AIX 5.23), is there anything I can do in python to ensure that the
ssh session does not timeout?

0
Reply jldunn2000797 (48) 10/1/2008 7:30:59 AM

On Wed, 01 Oct 2008 00:30:59 -0700, loial wrote:

> I have a problem with a ssh connection in python
> 
> I get the error
> 
> 'NoneType' object has no attribute 'exec_command'
> 
> I am thinking that maybe the ssh connection is timeing out.
> 
> Since I have no control over the configuration of the ssh server(which
> is AIX 5.23), is there anything I can do in python to ensure that the
> ssh session does not timeout?

No, it's a NoneType object (i.e. your variable contains None)
Show us a bit of your code, so we can see why is None there.

My guess is that you're trying to perform something on a function that 
does things in-place and doesn't return anything (e.g. list.append, 
list.sort)

>>> a = [1, 3, 4, 2]
>>> a = a.sort()
>>> print a
[None, None, None, None]

>>> # should be
>>> a = [1, 3, 4, 2]
>>> a.sort()
>>> print a
[1, 2, 3, 4]

0
Reply lie.1296 (854) 10/1/2008 8:07:43 AM


On Wed, 01 Oct 2008 08:07:43 +0000, Lie Ryan wrote:

>>>> a = [1, 3, 4, 2]
>>>> a = a.sort()
>>>> print a
> [None, None, None, None]

*That* would be really odd.  The last line should be just a singel `None` 
and not a list.  :-)

Ciao,
	Marc 'BlackJack' Rintsch
0
Reply bj_666 (1523) 10/1/2008 10:47:28 AM

On Wed, 01 Oct 2008 10:47:28 +0000, Marc 'BlackJack' Rintsch wrote:

> On Wed, 01 Oct 2008 08:07:43 +0000, Lie Ryan wrote:
> 
>>>>> a = [1, 3, 4, 2]
>>>>> a = a.sort()
>>>>> print a
>> [None, None, None, None]
> 
> *That* would be really odd.  The last line should be just a singel
> `None` and not a list.  :-)
> 
> Ciao,
> 	Marc 'BlackJack' Rintsch

Ah yeah, I originally intended to give a list of list example, but 
changed mind and forgot to change that last line.

0
Reply lie.1296 (854) 10/1/2008 11:03:39 AM

<<Show us a bit of your code, so we can see why is None there.>>

    def command ( self , command ) :
        """ process requested command through ssh """
        print command
        if not self._connected :
            return False , "No SSH connection available"
        try :
            stdin , stdout , stderr =
self._ssh.exec_command( command )
            remoteStdOutContent = stdout.readlines()
            remoteStdErrContent = stderr.readlines()
            if remoteStdErrContent != [] :
                return False , '\n'.join(remoteStdErrContent)
            return True , '\n'.join(remoteStdOutContent)
        except paramiko.SSHException , e :
            # provide socket error reason back
            return False , str(e)
0
Reply jldunn2000797 (48) 10/2/2008 8:26:25 AM

En Thu, 02 Oct 2008 05:26:25 -0300, loial <jldunn2000@googlemail.com>  
escribi�:

> <<Show us a bit of your code, so we can see why is None there.>>

Still not enough.
 From your first post, the error was:

> 'NoneType' object has no attribute 'exec_command'

>     def command ( self , command ) :
>         """ process requested command through ssh """
>         print command
>         if not self._connected :
>             return False , "No SSH connection available"
>         try :
>             stdin , stdout , stderr =
> self._ssh.exec_command( command )

So you'll have to analyze how (and when) self._ssh might become None. This  
function just *uses* self._ssh - look for some other places where  
self._ssh is assigned to (or perhaps, deleted, if there is a class  
attributes set to None).


-- 
Gabriel Genellina

0
Reply gagsl-py2 (3706) 10/2/2008 9:28:45 AM

5 Replies
8 Views

(page loaded in 0.106 seconds)


Reply: