1

我正在尝试使用下面的脚本通过结构连接到亚马逊 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

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

干杯,米奇

4

3 回答 3

5

我看到一些地方错误的填充错误是由 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]
于 2011-02-21T08:54:36.367 回答
5

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

于 2011-08-29T17:43:52.250 回答
0

我有一个类似的问题,并追踪到我的 .ssh/known_hosts 文件中的一些损坏。

我因此添加到我的 .bashrc

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

(显然将正确的结构脚本放在哪里<myfabscript>)现在当我简单地运行“部署”时一切正常!

于 2012-03-27T14:49:13.763 回答