在python脚本中出现错误“AttributeError: 'module' object has no attribute 'auth_none'”

0 投票
2 回答
4102 浏览
提问于 2025-04-17 04:59

我正在写一个Python脚本,用来通过paramiko登录到SSH服务器。下面是我写的脚本。

#!/usr/bin/python

import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
paramiko.transport.auth_none('sachin')
ssh.connect('localhost', username='sachin', password='abc123')
stdin, stdout, stderr = ssh.exec_command('df -h')
print stdout.readlines()
ssh.close()

现在我遇到了一个错误,错误信息是:AttributeError: 'module' object has no attribute 'auth_none'。

有没有人知道我为什么会出现这个错误?

谢谢!!!

2 个回答

2

auth_none 这个方法必须在一个特定的 Transport 实例上调用,而不是在 transport 模块上。

因为 SSHClient 没有类似的功能,所以你需要直接使用原始的 Transport

2

paramiko.transport模块里没有叫做auth_none的东西,这一点可以从它的文档中看到(错误信息也说明了这一点)。

也许你想要的是

ssh.get_transport().auth_none('sachin')

撰写回答