adi*_*anp 6 python ssh paramiko attributeerror
运行以下功能时:
def conEnclosure():
freebay = open("freebay", "w+")
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
password = getpass.getpass("Enter the password for infra: ")
for host in open("full.json", "r"):
print host
ssh.connect("%s" % host, username="infra", password="%s" % password)
stdin, stdout, stderr = ssh.exec_command("show server info all")
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Traceback (most recent call last):
File "./findbay_v2.py", line 53, in <module>
conEnclosure()
File "./findbay_v2.py", line 41, in conEnclosure
ssh.exec_command("show server info all")
File "build/bdist.macosx-10.9-intel/egg/paramiko/client.py", line 364, in exec_command
AttributeError: 'NoneType' object has no attribute 'open_session'
Run Code Online (Sandbox Code Playgroud)
但是,在python shell中运行时,请执行以下命令:
>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect("host", username="xxx", password="xxx")
>>> stdin, stdout, stderr = ssh.exec_command("show server info all")
Run Code Online (Sandbox Code Playgroud)
一切都按预期进行,只有当我在file.py中的上述函数中对其进行转换时才会发生错误.有谁知道它可能是什么?
| 归档时间: |
|
| 查看次数: |
8461 次 |
| 最近记录: |