2016-08-29 21 views
0

サーバで並列sshを実行しようとしています。これをしている間、私は "TypeError: 'NoneType'オブジェクトはiterableではありません"このエラーを取得しています。親切に助けてください。パラレルsshを実行しているときに "TypeError: 'NoneType'オブジェクトが反復可能ではありません"

私のスクリプトは

from pssh import ParallelSSHClient 
from pssh.exceptions import AuthenticationException, UnknownHostException, ConnectionErrorException 

def parallelsshjob(): 
     client = ParallelSSHClient(['10.84.226.72','10.84.226.74'], user = 'root', password = 'XXX') 
     try: 
       output = client.run_command('racadm getsvctag', sudo=True) 
       print output 
     except (AuthenticationException, UnknownHostException, ConnectionErrorException): 
       pass 
     #print output 

if __name__ == '__main__': 
     parallelsshjob() 

を下回っているトレースバックが溶液で私を助けても、これと同じスクリプトでのssh-agentを使用するために私を示唆

Traceback (most recent call last): 
    File "parallelssh.py", line 17, in <module> 
    parallelsshjob() 
    File "parallelssh.py", line 10, in parallelsshjob 
    output = client.run_command('racadm getsvctag', sudo=True) 
    File "/Library/Python/2.7/site-packages/pssh/pssh_client.py", line 520, in run_command 
    raise ex 
TypeError: 'NoneType' object is not iterable 

を下回っています。前もって感謝します。

答えて

1

私のラップトップでコードを読んで少しデバッグすることから、~/.ssh/configというファイルがないというのが問題だと思います。 parallel-sshはOpenSSHの設定に依存しているようですが、これはそのファイルが見つからないときのエラーです。

read_openssh_config返し、ここでなし:https://github.com/pkittenis/parallel-ssh/blob/master/pssh/ssh_client.py#L97:それが受信することを期待値を展開しようとすると、今度はhttps://github.com/pkittenis/parallel-ssh/blob/master/pssh/utils.py#L79

は、SSHClient.__init__吹くまで。

この修正は、おそらくOpenSSH設定ファイルをある種のものにするでしょうが、私はそれについて何も知らないと申し訳ありません。

EDIT

parallel-sshの例外処理の一部を掃除した後、ここでエラーのためのより良いスタックトレースがあります:

Traceback (most recent call last): 
    File "test.py", line 11, in <module> 
    parallelsshjob() 
    File "test.py", line 7, in parallelsshjob 
    output = client.run_command('racadm getsvctag', sudo=True) 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/pssh/pssh_client.py", line 517, in run_command 
    self.get_output(cmd, output) 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/pssh/pssh_client.py", line 601, in get_output 
    (channel, host, stdout, stderr, stdin) = cmd.get() 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/gevent/greenlet.py", line 480, in get 
    self._raise_exception() 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/gevent/greenlet.py", line 171, in _raise_exception 
    reraise(*self.exc_info) 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/gevent/greenlet.py", line 534, in run 
    result = self._run(*self.args, **self.kwargs) 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/pssh/pssh_client.py", line 559, in _exec_command 
    channel_timeout=self.channel_timeout) 
    File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/pssh/ssh_client.py", line 98, in __init__ 
    host, config_file=_openssh_config_file) 
TypeError: 'NoneType' object is not iterable 
0

このwas seemingly a regression in the 0.92.0 version of the library0.92.1で解決されます。以前のバージョンも動作します。 OpenSSHの設定は、であるべきではありません。

あなたのSSHエージェントの質問に答えるために、実行中のものがあり、ユーザーセッションで有効になっているものがあれば、それは自動的に使用されます。あなたは秘密鍵を提供することを好む場合は、プログラムで、次の

from pssh import ParallelSSHClient 
from pssh.utils import load_private_key 
pkey = load_private_key('my_private_key') 
client = ParallelSSHClient(hosts, pkey=pkey) 

はまた、より多くの例については

以下
from pssh import ParallelSSHClient 
from pssh.utils import load_private_key 
from pssh.agent import SSHAgent 
pkey = load_private_key('my_private_key') 
agent = SSHAgent() 
agent.add_key(pkey) 
client = ParallelSSHClient(hosts, agent=agent) 

See documentationごとに、プログラムで複数のキーでエージェントを提供することができます行うことができます。

関連する問題