这个问题可能很愚蠢,但我讨厌编程语言对我这样做......所以我有以下功能:
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
当然client
是 String: client = config['client']
。有人可以帮我吗?Python 版本是2.7.5
.