Qual é a diferença entre chamar open_sftp () localmente e através de uma função separada?
No código a seguir, o primeiro teste passa e o segundo não, o que acho intrigante.
import paramiko
def test1():
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('10.0.0.107', username='test', password='test')
sftp = client.open_sftp()
sftp.stat('/tmp')
sftp.close()
def get_sftp():
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('10.0.0.107', username='test', password='test')
return client.open_sftp()
def test2():
sftp = get_sftp()
sftp.stat('/tmp')
sftp.close()
if __name__ == '__main__':
test1()
print 'test1 done'
test2()
print 'test2 done'
Aqui está o que eu recebo:
$ ./script.py
test1 done
Traceback (most recent call last):
File "./play.py", line 25, in <module>
test2()
File "./play.py", line 20, in test2
sftp.stat('/tmp')
File "/usr/lib/pymodules/python2.6/paramiko/sftp_client.py", line 337, in stat
t, msg = self._request(CMD_STAT, path)
File "/usr/lib/pymodules/python2.6/paramiko/sftp_client.py", line 627, in _request
num = self._async_request(type(None), t, *arg)
File "/usr/lib/pymodules/python2.6/paramiko/sftp_client.py", line 649, in _async_request
self._send_packet(t, str(msg))
File "/usr/lib/pymodules/python2.6/paramiko/sftp.py", line 172, in _send_packet
self._write_all(out)
File "/usr/lib/pymodules/python2.6/paramiko/sftp.py", line 138, in _write_all
raise EOFError()
EOFError
Isso acontece tanto no Ubuntu (Python2,6 e paramiko1.7.6) e Debian (Python2,7 e paramiko1.7.7).
Se eu corrertest2
primeiro, eu só recebo o rastreamento de pilha, significandotest2
de fato falha.