python paramiko error “AttributeError: 'NoneType' object has no attribute 'open_session'”
python paramiko error “AttributeError: 'NoneType' object has no attribute 'open_session'”
I'm trying python paramiko module, got below error. How can I solve this? (I searched a lot, but no lucky)
Any replies will be appreciated. (On Mac OS)
python2.7 aaa.py
Traceback (most recent call last):
File "aaa.py", line 24, in <module>
ssh_command('172.16.129.130', 22, 'user', 'password', 'ls')
File "aaa.py", line 14, in ssh_command
stdin,stdout,stderr = client.exec_command(command)
File "/Users/usera/anaconda2/lib/python2.7/site- packages/paramiko/client.py", line 480, in exec_command
chan = self._transport.open_session(timeout=timeout)
AttributeError: 'NoneType' object has no attribute 'open_session'
Python version
Python 2.7.14 |Anaconda, Inc.| (default, Dec 7 2017, 11:07:58)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Python code
cat aaa.py
#-*- coding:utf-8 -*-
import paramiko
#def ssh_command(ip, port, username, password, command='pwd; ls'):
def ssh_command(ip, port, username, password, command):
paramiko.util.log_to_file("filename.log")
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect = (ip, port, username, password)
#stdin, stdout, stderr = client.exec_command(command)
stdin,stdout,stderr = client.exec_command(command)
#input = stdin.read()
output = stdout.read()
#output_error = stderr.read()
print ouput.decode('utf-8')
# Close the connect
client.close()
ssh_command('172.16.129.130', 22, 'user', 'password', 'ls')
1 Answer
1
The problem is my typo.
"client.connect = (ip, port, username, password)" should be "client.connect(ip, port, username, password)"
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.