python - 如何在 Fabric 2 中使用 Connection?

标签 python python-2.7 fabric

我正在尝试连接到主机并使用模块 Fabric 2 运行命令并出现此错误:

Traceback (most recent call last):
  File "Utilities/fabfile.py", line 4, in <module>
    res.run('uname -s')
  File "<decorator-gen-3>", line 2, in run
  File "/usr/local/lib/python2.7/dist-packages/fabric/connection.py", line 29, in opens
    self.open()
  File "/usr/local/lib/python2.7/dist-packages/fabric/connection.py", line 501, in open
    self.client.connect(**kwargs)
  File "/home/trishnevskaya/.local/lib/python2.7/site-packages/paramiko/client.py", line 424, in connect
passphrase,
  File "/home/username/.local/lib/python2.7/site-packages/paramiko/client.py", line 715, in _auth
raise SSHException('No authentication methods available')
paramiko.ssh_exception.SSHException: No authentication methods available

来自文档的简单代码(http://docs.fabfile.org/en/latest/getting-started.html):

from fabric import Connection

res = Connection('<host-ip>')
res.run('uname -s')

根据文档,我不需要特殊配置,但它不起作用...

织物 2.1.3
python 2.7.14

最佳答案

以下对我有用。

connect_kwargs = {"key_filename":['PATH/KEY.pem']}
with Connection(host="EC2", user="ubuntu", connect_kwargs=connect_kwargs) as c:
    c.run("mkdir abds")

关于python - 如何在 Fabric 2 中使用 Connection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50710124/

相关文章:

python - 在 Pyramid 项目中存储全局配置变量

python - 如何将分类数据从 numpy 数组加载到指标或嵌入列中?

python - 使用 sudo python 打开终端

远程运行命令的 Python Fabric 返回值

python - 如何在 SQLAlchemy/Postgres 中限制每个 `group_by` 的 N 个结果?

python - 将 ARMA() 模型拟合到假定平稳的时间序列时的平稳性问题

python - 如何在 python 中打印原始 unicode?

python - 使 python 循环更快

python - Fabric 密码

Python 结构将 root 密码作为命令行参数传递不起作用