示例:如何在交互式会话和非交互式会话之间切换?

时间:2017-11-20 19:48:06

标签: python exscript

我正在尝试使用Unix服务器打开一个会话,然后将控件释放给脚本用户,直到按下Ctrl + y,之后程序应该控制 我正在使用Eclipse和WinPython 2.7。这是代码

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() 

上面的失败

     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)

我做错了什么?

1 个答案:

答案 0 :(得分:2)

看起来像是Exscript中的错误。

来自Protocol.py

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

该函数不接受第4个handle_window_size参数(careful about how python counts arguments in that situation)。

显然你并没有使用最新版本,但就我所知,即便是最新版本也有错误。 通过源历史记录,我说这个bug是在2.2中引入的,它在2.1中没有。我没有测试它,只是阅读源代码,我不是python专家,所以我可能完全错了。

如果我是对的,除了:

之外,你做不了多少
  • 使用2.1(显然是7岁)
  • 在本地修补它(也许删除最后一个参数......不确定&#39; ll是否正常工作!)
  • filing an issue
相关问题