Python Fabric 运行命令返回“binascii.Error:不正确的填充”
我正在尝试使用下面的脚本通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我看到一些地方的 Binascii 模块导致了不正确的填充错误,这主要是当您传递的字符串包含一些无关的空白字符时。
就您而言,它是您为
env
对象设置的各种属性。对您的关键文件位置执行类似的操作,看看是否有效。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.
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.查看您的 ~/.ssh/known_hosts 文件。它可能包含具有重复条目的行或以其他方式损坏。
Look at your ~/.ssh/known_hosts file. It may contain lines with duplicate entries or be corrupted in some other way.
我遇到了类似的问题,并追踪到我的 .ssh/known_hosts 文件中存在一些损坏。
因此,我添加到我的 .bashrc
(显然将正确的结构脚本放在
所在的位置),现在当我只需运行“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
(obviously putting the right fabric script where
<myfabscript>
is) and now all works fine when I simply run "deploy"!