我正在尝试使用以下脚本通过结构连接以连接到Amazon 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
任何帮助/提示将不胜感激。
干杯,
米奇
最佳答案
我看到一些地方,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]
关于python - Python Fabric运行命令返回“binascii.Error:不正确的填充”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5063796/