Python Fabric 运行命令返回“binascii.Error:不正确的填充”

发布于 2024-10-18 17:31:31 字数 1880 浏览 2 评论 0原文

我正在尝试使用下面的脚本通过 Fabric 连接到亚马逊 EC2。但我遇到了一个问题,我不知道如何解决。

import os
from fabric.api import run, env, local, cd

WORK = os.getenv('HOME') + '/Work/myproject/'

env.user = 'ubuntu'
env.hosts = [
    '128.248.268.288'
]
env.key_filename = [
    '%s/aws/myproject.pem' % WORK
]

def deploy():
    print("Executing on %(host)s as %(user)s" % env)
    with cd('/sites/myproject.com/code/'):
        run('ls')

这是回溯。我不知道如何解决这个问题。

Traceback (most recent call last):
  File "/Library/Python/2.6/site-packages/fabric/main.py", line 540, in main
    commands[name](*args, **kwargs)
  File "/Users/mickeyckm/Work/myproject/codes/giivee/fabfile.py", line 18, in deploy
    run('ls')
  File "/Library/Python/2.6/site-packages/fabric/network.py", line 391, in host_prompting_wrapper
    return func(*args, **kwargs)
  File "/Library/Python/2.6/site-packages/fabric/operations.py", line 422, in run
    channel = connections[env.host_string]._transport.open_session()
  File "/Library/Python/2.6/site-packages/fabric/network.py", line 65, in __getitem__
    self[real_key] = connect(user, host, port)
  File "/Library/Python/2.6/site-packages/fabric/network.py", line 140, in connect
    client.load_system_host_keys()
  File "/Library/Python/2.6/site-packages/paramiko/client.py", line 151, in load_system_host_keys
    self._system_host_keys.load(filename)
  File "/Library/Python/2.6/site-packages/paramiko/hostkeys.py", line 155, in load
    e = HostKeyEntry.from_line(line)
  File "/Library/Python/2.6/site-packages/paramiko/hostkeys.py", line 67, in from_line
    key = RSAKey(data=base64.decodestring(key))
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/base64.py", line 321, in decodestring
    return binascii.a2b_base64(s)
binascii.Error: Incorrect padding

任何帮助/提示将不胜感激。

干杯, 米奇

I'm trying to connect to connect to amazon EC2 via fabric using the script below. But I'm met with a problem that I'm not sure how to solve it.

import os
from fabric.api import run, env, local, cd

WORK = os.getenv('HOME') + '/Work/myproject/'

env.user = 'ubuntu'
env.hosts = [
    '128.248.268.288'
]
env.key_filename = [
    '%s/aws/myproject.pem' % WORK
]

def deploy():
    print("Executing on %(host)s as %(user)s" % env)
    with cd('/sites/myproject.com/code/'):
        run('ls')

This is the traceback. I'm not sure how to solve the problem.

Traceback (most recent call last):
  File "/Library/Python/2.6/site-packages/fabric/main.py", line 540, in main
    commands[name](*args, **kwargs)
  File "/Users/mickeyckm/Work/myproject/codes/giivee/fabfile.py", line 18, in deploy
    run('ls')
  File "/Library/Python/2.6/site-packages/fabric/network.py", line 391, in host_prompting_wrapper
    return func(*args, **kwargs)
  File "/Library/Python/2.6/site-packages/fabric/operations.py", line 422, in run
    channel = connections[env.host_string]._transport.open_session()
  File "/Library/Python/2.6/site-packages/fabric/network.py", line 65, in __getitem__
    self[real_key] = connect(user, host, port)
  File "/Library/Python/2.6/site-packages/fabric/network.py", line 140, in connect
    client.load_system_host_keys()
  File "/Library/Python/2.6/site-packages/paramiko/client.py", line 151, in load_system_host_keys
    self._system_host_keys.load(filename)
  File "/Library/Python/2.6/site-packages/paramiko/hostkeys.py", line 155, in load
    e = HostKeyEntry.from_line(line)
  File "/Library/Python/2.6/site-packages/paramiko/hostkeys.py", line 67, in from_line
    key = RSAKey(data=base64.decodestring(key))
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/base64.py", line 321, in decodestring
    return binascii.a2b_base64(s)
binascii.Error: Incorrect padding

Any help/hint would be great appreciated.

Cheers,
Mickey

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凯凯我们等你回来 2024-10-25 17:31:31

我看到一些地方的 Binascii 模块导致了不正确的填充错误,这主要是当您传递的字符串包含一些无关的空白字符时。

>>> import binascii
>>> binascii.a2b_base64('a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
binascii.Error: Incorrect padding

就您而言,它是您为 env 对象设置的各种属性。对您的关键文件位置执行类似的操作,看看是否有效。

filelocation = os.path.join(WORK,'aws/myproject.pem')
env.key_filename = [filelocation]

I saw some places where Incorrect Padding error was resulted from binascii module and it was mostly when the string you pass has some extraneous white-space characters.

>>> import binascii
>>> binascii.a2b_base64('a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
binascii.Error: Incorrect padding

In your case, it the various properties you set for your env object. Do something like this for your key file location and see if that works.

filelocation = os.path.join(WORK,'aws/myproject.pem')
env.key_filename = [filelocation]
幸福丶如此 2024-10-25 17:31:31

查看您的 ~/.ssh/known_hosts 文件。它可能包含具有重复条目的行或以其他方式损坏。

Look at your ~/.ssh/known_hosts file. It may contain lines with duplicate entries or be corrupted in some other way.

三五鸿雁 2024-10-25 17:31:31

我遇到了类似的问题,并追踪到我的 .ssh/known_hosts 文件中存在一些损坏。

因此,我添加到我的 .bashrc

alias deploy='mv ~/.ssh/known_hosts ~/.ssh/known_hosts.tmp; fab <myfabscript>; mv ~/.ssh/known_hosts.old ~/.ssh/known_hosts'

(显然将正确的结构脚本放在 所在的位置),现在当我只需运行“deploy”时,一切正常!

I had a similar problem and tracked it down to some corruption in my .ssh/known_hosts file.

I thus added to my .bashrc

alias deploy='mv ~/.ssh/known_hosts ~/.ssh/known_hosts.tmp; fab <myfabscript>; mv ~/.ssh/known_hosts.old ~/.ssh/known_hosts'

(obviously putting the right fabric script where <myfabscript> is) and now all works fine when I simply run "deploy"!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文