0

この質問はばかげているかもしれませんが、プログラミング言語が私にそれを行うのは嫌いです...だから私は次の機能を持っています:

def udp_server(client=""):
    mutex.acquire()
    try:
        print "Starting server ... "
        server_process = subprocess.Popen("iperf.exe -s -u -i 1 -l 872",
                                          stderr=subprocess.STDOUT,
                                          stdout=subprocess.PIPE)
        print "Server started at ", server_process.pid
        print "Starting the client remotely on %s" % client
        cmd = "cd C:/performance/Iperf && python iperf_udp_client.py -c %s" % client
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.WarningPolicy())
        client.connect(str(client), username=str(config['ssh_user']),
                       password=str(config['ssh_pwd']))
        stdin, stdout, stderr = client.exec_command(cmd)
        print stdout.readlines()
        server_process.kill()
    except Exception, e:
        print e
    finally:
        mutex.release()

config関数が読み込まれるときに読み込まれます...値はmode.configファイルに割り当てられ、うまく解析されますconfig(私はそれをテストしました)

if __name__ == '__main__':
    config = {}
    execfile('C:\performance\mode.config', config)
    main()

値をハードコーディングするclient.connect()とうまくいきましたが、正しい方法で (ハードコーディングではなく構成ファイルを使用して) 作成しようとすると、次のエラーが発生します。

Starting the client remotely on 123.456.795
getaddrinfo() argument 1 must be string or None

もちろんclientString:client = config['client']です。誰か助けてくれませんか?Python のバージョンは2.7.5.

4

2 に答える 2

4

client = config['client']で定義(これはあなたが念頭に置いていることです)を上書きしていますclient = paramiko.SSHClient()。2 つの変数のいずれかの名前を変更します。

于 2013-10-01T21:56:06.153 に答える
1

client接続先のクライアントのホスト名と、接続にSSHClient使用しているインスタンスの2 つの異なる変数 both に名前を付けました。

あなたがするとき

client.connect(str(client), ...)

クライアントのホスト名ではなく、strの を効果的に渡しています。SSHClientこれにより、ホスト名の解決に失敗します (おそらく のようになります<SSHClient instance at 0xdeadbeef>)。

これは、変数の名前を変更することで解決できます。たとえば、のhostname代わりにホスト名を呼び出すことができますclient

于 2013-10-01T21:54:49.820 に答える