6

I am trying to programaticaly open a session with a Unix server and then release the control to the user of the script till Ctrl+y is pressed after which the program should take control I am using Eclipse and WinPython 2.7. here is the code

from Exscript.util.interact import read_login
from Exscript.protocols import SSH2


def Test ():
    print "Interactive session closed"

account = read_login()    # Prompt the user for his name and password
conn = SSH2()
conn.set_driver('generic')             # We choose to use SSH2
conn.connect('remmotehostip') # Open the SSH connection
conn.login(account)       # Authenticate on the remote host
conn.execute('uname -a')  # Execute the "uname -a" command
print conn.response
conn.interact({'\031': Test()})
conn.send('exit\r')       # Send the "exit" command
conn.close() 

the above fails with

     Traceback (most recent call last):
  File "C:\Users\mynamehere\Documents\Eclipse\ESNetworkDiscovery\TestInteractiveSession.py", line 20, in <module>
    conn.interact({'\031': Test()})   
      File "C:\Utils\WPy2.7-32\python-2.7.13\lib\site-packages\Exscript\protocols\SSH2.py", line 364, in interact
        return self._open_shell(self.shell, key_handlers, handle_window_size)   
      File "C:\Utils\WPy2.7-32\python-2.7.13\lib\site-packages\Exscript\protocols\Protocol.py", line 1190, in _open_shell
        return self._open_windows_shell(channel, key_handlers, handle_window_size)
    TypeError: _open_windows_shell() takes exactly 3 arguments (4 given)

What am I doing wrong ?

MiniMe
  • 1,057
  • 4
  • 22
  • 47
  • Can you give a more complete traceback of the exception you're getting? I'm assuming it's coming from the `conn.interact(...)` line, but the call from your code into the library code is not included in the traceback you've posted. I'm sort of suspicious that `conn.interact({'\031': Test()})` doesn't do what you expect (it calls `Test()` immediately, before `conn.interact`), but I don't know enough about the library to say if that's the cause of your exception. – Blckknght Dec 14 '17 at 01:56
  • I added the missing line; it was irrelevant ..that is why I removed it – MiniMe Dec 14 '17 at 06:14
  • I'm not sure it's related to your exception, but you do have a clear error on that line with the argument. You should be passing the dict `{'\031': Test}` rather than `{'\031': Test()}`. Don't call `Test` yourself, just pass a reference to it! – Blckknght Dec 14 '17 at 06:23
  • yeah you are correct, it does not fix the error – MiniMe Dec 14 '17 at 08:11

1 Answers1

2

Looks like a bug in Exscript.

From Protocol.py:

        return self._open_windows_shell(channel, key_handlers, handle_window_size)
...
    def _open_windows_shell(self, channel, key_handlers):

That function does not accept the 4th handle_window_size argument (careful about how python counts arguments in that situation).

Apparently you're not using the latest version, but even the latest has the bug as far as I can tell. Looking through source history, I'd say the bug was introduced in 2.2, it's not there in 2.1. I have not tested it, just read the source, and I'm not a python expert so I might be totally wrong.

If I'm right, you can't do much, apart from:

  • using 2.1 (which is apparently 7 years old)
  • patching it locally (maybe remove the last argument... not sure that'll work!)
  • filing an issue
Hugues M.
  • 19,846
  • 6
  • 37
  • 65