Python Fabric运行命令返回"binascii.Error:不正确的填充". [英] Python Fabric run command returns "binascii.Error: Incorrect padding"

查看:141
本文介绍了Python Fabric运行命令返回"binascii.Error:不正确的填充".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下脚本通过结构连接以连接到Amazon EC2.但是我遇到了不确定如何解决的问题.

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.

干杯, 米奇

推荐答案

我看到一些地方的binascii模块导致了Padding错误,这主要是因为您传递的字符串中有一些多余的空格字符.

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

在您的情况下,它是为env对象设置的各种属性.对您的密钥文件位置执行类似的操作,然后查看是否可行.

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]

这篇关于Python Fabric运行命令返回"binascii.Error:不正确的填充".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆