Python paramiko中exec_命令和invoke_shell方法的EOF错误

Python paramiko中exec_命令和invoke_shell方法的EOF错误,python,python-3.x,paramiko,Python,Python 3.x,Paramiko,我试图使用python paramiko在windows机器上的linux服务器上执行一个命令,我使用了这两种方法 1.exec_命令 2.2.1壳 它们都给出了EOF错误 import paramiko import time def ConnectSSH1(host, port, username, password): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPol

我试图使用python paramiko在windows机器上的linux服务器上执行一个命令,我使用了这两种方法

1.exec_命令

2.2.1壳

它们都给出了EOF错误

import paramiko
import time
def ConnectSSH1(host, port, username, password):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(host, int(port), username, password)
    chan = ssh.invoke_shell() # Throws EOF error here 
    #stdin, stdout, stderr = ssh.exec_command("ls")   #Throws EOF error here with exec_command
    chan.send("ls -a")
    time.sleep(5)
    output = chan.recv(9999)
    print (output)
    print (command)
    return (output)
exec_命令出错

C:\RobotFramework>python paramiko_solution1.py
Traceback (most recent call last):
  File "paramiko_solution1.py", line 15, in <module>
    chan.exec_command(command)
  File "C:\Python37\lib\site-packages\paramiko\channel.py", line 72, in _check
    return func(self, *args, **kwds)
  File "C:\Python37\lib\site-packages\paramiko\channel.py", line 257, in exec_command
    self._wait_for_event()
  File "C:\Python37\lib\site-packages\paramiko\channel.py", line 1226, in _wait_for_event
    raise e
  File "C:\Python37\lib\site-packages\paramiko\transport.py", line 2055, in run
    ptype, m = self.packetizer.read_message()
  File "C:\Python37\lib\site-packages\paramiko\packet.py", line 459, in read_message
    header = self.read_all(self.__block_size_in, check_rekey=True)
  File "C:\Python37\lib\site-packages\paramiko\packet.py", line 303, in read_all
    raise EOFError()
EOFError
C:\RobotFramework>python paramiko_solution1.py
回溯(最近一次呼叫最后一次):
文件“paramiko_solution1.py”,第15行,在
chan.exec_命令(command)
文件“C:\Python37\lib\site packages\paramiko\channel.py”,第72行,检查
返回函数(self,*args,**kwds)
exec_命令中的第257行文件“C:\Python37\lib\site packages\paramiko\channel.py”
self.\u等待\u事件()
文件“C:\Python37\lib\site packages\paramiko\channel.py”,第1226行,在等待事件中
提高e
文件“C:\Python37\lib\site packages\paramiko\transport.py”,第2055行,正在运行
ptype,m=self.packetizer.read_message()
文件“C:\Python37\lib\site packages\paramiko\packet.py”,第459行,在read\u消息中
header=self.read\u all(self.\u块大小\u in,check\u rekey=True)
文件“C:\Python37\lib\site packages\paramiko\packet.py”,第303行,全部读取
提高EOR()
伊奥费罗
调用shell命令时出错

>>> channel.get_pty()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python37\lib\site-packages\paramiko\channel.py", line 72, in _check
    return func(self, *args, **kwds)
  File "C:\Python37\lib\site-packages\paramiko\channel.py", line 203, in get_pty
    self._wait_for_event()
  File "C:\Python37\lib\site-packages\paramiko\channel.py", line 1226, in _wait_for_event
    raise e
  File "C:\Python37\lib\site-packages\paramiko\transport.py", line 2055, in run
    ptype, m = self.packetizer.read_message()
  File "C:\Python37\lib\site-packages\paramiko\packet.py", line 459, in read_message
    header = self.read_all(self.__block_size_in, check_rekey=True)
  File "C:\Python37\lib\site-packages\paramiko\packet.py", line 303, in read_all
    raise EOFError()
EOFError
>>>
频道。获取 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 文件“C:\Python37\lib\site packages\paramiko\channel.py”,第72行,检查 返回函数(self,*args,**kwds) 文件“C:\Python37\lib\site packages\paramiko\channel.py”,第203行,在get\pty中 self.\u等待\u事件() 文件“C:\Python37\lib\site packages\paramiko\channel.py”,第1226行,在等待事件中 提高e 文件“C:\Python37\lib\site packages\paramiko\transport.py”,第2055行,正在运行 ptype,m=self.packetizer.read_message() 文件“C:\Python37\lib\site packages\paramiko\packet.py”,第459行,在read\u消息中 header=self.read\u all(self.\u块大小\u in,check\u rekey=True) 文件“C:\Python37\lib\site packages\paramiko\packet.py”,第303行,全部读取 提高EOR() 伊奥费罗 >>> 帕尔马基奥原木

CRITICAL:root:None
DEBUG:paramiko.transport:starting thread (client mode): 0x8133c488
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.7.1
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-SSH
INFO:paramiko.transport:Connected (version 2.0, client SSH)
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group-exchange-sha256', 'diffie-hellman-group1-sha1', 'diffie-hellman-group14-sha1'] server key:['ssh-rsa'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', '3des-cbc', 'arcfour'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', '3des-cbc', 'arcfour'] client mac:['hmac-md5', 'hmac-md5-96', 'hmac-sha1', 'hmac-sha1-96', 'hmac-sha2-256', 'hmac-sha2-512'] server mac:['hmac-md5', 'hmac-md5-96', 'hmac-sha1', 'hmac-sha1-96', 'hmac-sha2-256', 'hmac-sha2-512'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group-exchange-sha256
DEBUG:paramiko.transport:HostKey agreed: ssh-rsa
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:Got server p (2048 bits)
DEBUG:paramiko.transport:kex engine KexGexSHA256 specified hash_algo <built-in function openssl_sha256>
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Adding ssh-rsa host key for 12.22.124.66: b'16d9d878229cssdcc837d33a64'
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (password) successful!
CRITICAL:root:None
DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes
DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes
DEBUG:paramiko.transport:Secsh channel 0 opened.
DEBUG:paramiko.transport:EOF in transport thread
CRITICAL:根目录:无
调试:paramiko.transport:启动线程(客户端模式):0x8133c488
调试:paramiko.transport:本地版本/idstring:SSH-2.0-paramiko_2.7.1
调试:paramiko.transport:远程版本/idstring:SSH-2.0-SSH
信息:paramiko.transport:Connected(版本2.0,客户端SSH)
调试:paramiko.transport:kex算法:['diffie-hellman-group-exchange-sha256','diffie-hellman-group1-sha1','diffie-hellman-group14-sha1']服务器密钥:['ssh-rsa']客户端加密:['aes128-ctr','aes192-ctr','aes256-ctr aes128-cbc','blowfish-cbc','cast128-cbc','aes192-cbc','aes256-cbc','3des cbc',arcfour']服务器加密:[aes128-ctr]、[aes192-ctr]、[aes256-ctr]、[aes128-cbc]、[cast128-cbc]、[aes192-cbc]、[aes256-cbc]、[3des-cbc]、[ARCFORD']客户端mac:[hmac-md5]、[hmac-md5-96]、[hmac-sha1-sha1]、[hmac-sha1-96]、[hmac-sha1-256]、[hmac-sha2-512']客户端压缩:['none']服务器压缩:['none']客户端语言:['']服务器语言:[''kex如下?False
调试:paramiko.传输:Kex同意:diffie-hellman-group-exchange-sha256
调试:paramiko.transport:HostKey同意:ssh-rsa
调试:paramiko.传输:同意密码:aes128 ctr
调试:paramiko。传输:MAC同意:hmac-sha2-256
调试:paramiko.传输:压缩:无
调试:paramiko.transport:获取服务器p(2048位)
调试:paramiko.transport:kex引擎KexGexSHA256指定的哈希算法
调试:paramiko.transport:切换到新密钥。。。
调试:paramiko.transport:为12.22.124.66添加ssh rsa主机密钥:b'16d9d878229cssdcc837d33a64'
调试:paramiko.transport:userauth正常
信息:paramiko。传输:身份验证(密码)成功!
关键:根:无
调试:paramiko.transport:[chan 0]最大数据包长度:32768字节
调试:paramiko.transport:[chan 0]最大数据包输出:32768字节
调试:paramiko。传输:已打开Secsh通道0。
调试:paramiko.transport:传输线程中的EOF
来自SSH窗口的日志

ssh -vv eijm@12.22.124.66 /usr/bin/who
OpenSSH_for_Windows_8.1p1, LibreSSL 2.9.2
debug2: resolve_canonicalize: hostname 12.22.124.66 is address
debug2: ssh_connect_direct
debug1: Connecting to 12.22.124.66 [12.22.124.66] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\eijm/.ssh/id_rsa type -1
debug1: identity file C:\\Users\\eijm/.ssh/id_rsa-cert type -1
debug1: identity file C:\\Users\\eijm/.ssh/id_dsa type -1
debug1: identity file C:\\Users\\eijm/.ssh/id_dsa-cert type -1
debug1: identity file C:\\Users\\eijm/.ssh/id_ecdsa type -1
debug1: identity file C:\\Users\\eijm/.ssh/id_ecdsa-cert type -1
debug1: identity file C:\\Users\\eijm/.ssh/id_ed25519 type -1
debug1: identity file C:\\Users\\eijm/.ssh/id_ed25519-cert type -1
debug1: identity file C:\\Users\\eijm/.ssh/id_xmss type -1
debug1: identity file C:\\Users\\eijm/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1
debug1: Remote protocol version 2.0, remote software version SSH
debug1: no match: SSH
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 12.22.124.66:22 as 'eijmto'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: diffie-hellman-group-exchange-sha256,diffie-hellman-group1-sha1,diffie-hellman-group14-sha1
debug2: host key algorithms: ssh-rsa
debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,3des-cbc,arcfour
debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,3des-cbc,arcfour
debug2: MACs ctos: hmac-md5,hmac-md5-96,hmac-sha1,hmac-sha1-96,hmac-sha2-256,hmac-sha2-512
debug2: MACs stoc: hmac-md5,hmac-md5-96,hmac-sha1,hmac-sha1-96,hmac-sha2-256,hmac-sha2-512
debug2: compression ctos: none
debug2: compression stoc: none
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: diffie-hellman-group-exchange-sha256
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<8192<8192) sent
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug2: bits set: 4078/8192
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:gj6tlHPgeFidgXKMwymWz55UiuGnFwFw38GwSToCQMk
debug1: Host '12.22.124.66' is known and matches the RSA host key.
debug1: Found key in C:\\Users\\eijm/.ssh/known_hosts:1
debug2: bits set: 4015/8192
debug2: set_newkeys: mode 1
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 4294967296 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: Will attempt key: C:\\Users\\eijm/.ssh/id_rsa
debug1: Will attempt key: C:\\Users\\eijm/.ssh/id_dsa
debug1: Will attempt key: C:\\Users\\eijm/.ssh/id_ecdsa
debug1: Will attempt key: C:\\Users\\eijm/.ssh/id_ed25519
debug1: Will attempt key: C:\\Users\\eijm/.ssh/id_xmss
debug2: pubkey_prepare: done
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: C:\\Users\\eijm/.ssh/id_rsa
debug1: Trying private key: C:\\Users\\eijm/.ssh/id_dsa
debug1: Trying private key: C:\\Users\\eijm/.ssh/id_ecdsa
debug1: Trying private key: C:\\Users\\eijm/.ssh/id_ed25519
debug1: Trying private key: C:\\Users\\eijm/.ssh/id_xmss
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such file or directory
eijmto@12.22.124.66's password:
debug2: we sent a password packet, wait for reply
debug1: Authentication succeeded (password).
Authenticated to 12.22.124.66 ([12.22.124.66]:22).
debug1: channel 0: new [client-session]
debug2: channel 0: send open
debug1: Entering interactive session.
debug1: pledge: network
debug2: channel_input_open_confirmation: channel 0: callback start
debug2: fd 3 setting TCP_NODELAY
debug2: client_session2_setup: id 0
debug1: Sending command: /usr/bin/who
debug2: channel 0: request exec confirm 1
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug2: channel 0: rcvd close
debug2: channel 0: chan_shutdown_read (i0 o1 sock -1 wfd 4 efd 6 [write])
debug2: channel 0: input open -> closed
ansda pts/9        2020-05-13 09:28 (185.39.130.179)
moroka pts/13       2019-07-29 17:04 (185.39.130.181)
eijmto pts/15       2020-05-13 09:35 (172.30.170.1)
debug2: channel 0: obuf empty
debug2: channel 0: chan_shutdown_write (i3 o1 sock -1 wfd 5 efd 6 [write])
debug2: channel 0: output drain -> closed
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
ion, nchannels 1
conds
ssh-vveijm@12.22.124.66/usr/bin/who
OpenSSH_for_Windows_8.1p1,LibreSSL 2.9.2
debug2:resolve_规范化:主机名12.22.124.66是地址
debug2:ssh\u connect\u direct
debug1:连接到12.22.124.66[12.22.124.66]端口22。
debug1:已建立连接。
debug1:标识文件C:\\Users\\eijm/.ssh/id\u rsa类型-1
debug1:标识文件C:\\Users\\eijm/.ssh/id\u rsa-cert类型-1
debug1:标识文件C:\\Users\\eijm/.ssh/id\u dsa类型-1
debug1:标识文件C:\\Users\\eijm/.ssh/id\u dsa-cert类型-1
debug1:标识文件C:\\Users\\eijm/.ssh/id\u ecdsa type-1
debug1:标识文件C:\\Users\\eijm/.ssh/id\u ecdsa-cert type-1
debug1:标识文件C:\\Users\\eijm/.ssh/id_ed25519 type-1
debug1:标识文件C:\\Users\\eijm/.ssh/id_ed25519-cert type-1
debug1:标识文件C:\\Users\\eijm/.ssh/id\u xmss type-1
debug1:标识文件C:\\Users\\eijm/.ssh/id\u xmss-cert type-1
debug1:本地版本字符串SSH-2.0-OpenSSH\u for\u Windows\u 8.1
debug1:远程协议版本2.0,远程软件版本SSH
debug1:不匹配:SSH
调试2:fd 3设置O_非块
debug1:将12.22.124.66:22验证为“eijmto”
debug1:SSH2\u MSG\u KEXINIT已发送
debug1:SSH2\u MSG\u KEXINIT已收到
调试2:本地客户科欣IT提案
debug2:KEX算法:curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2:主机密钥算法:rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh rsa证书-v01@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh rsa,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519
debug2:密码CTO:chacha20-poly1305@