2015-10-14 94 views
0

我试图发出从Python中的curl命令,从命令行它工作正常:无法解析主机:>

curl -k --data-binary @GetRequestData.xml -u archala:[email protected] https://wsgwtestmg.mass.gov:5550/service/mgmt/current > Response\generated_Resp.xml 

但是当我从蟒蛇把它叫做:

from sys import argv 
import subprocess 
# run python cache2.py hosts.txt Test 
with open(argv[1]) as f: 
    addresses = {i.split(" : ")[0] : i.split(" : ")[1] for i in f} 
    print(addresses[argv[2]]) 


command = "curl -k --data-binary @GetRequestData.xml -u archala:[email protected] https://" +addresses[argv[2]].strip()+ ":5550/service/mgmt/current > Response\generated_Resp.xml" 
print(command) 
p = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0] 

我得到: 无法解析主机:>

+3

'print(command)'的输出是什么? –

+0

你认为你在代码中设置了“https:// wsgwtestmg.mass.gov”在哪里? –

+0

https://wsgwtestmg.mass.gov来自地址[argv [2]] –

回答

0

在swstephe的帮助下,增加了shell = True,它工作。

有人提到使用请求是一种更好的方式,我会感激如果有人给我使用请求相同。 谢谢。