2015-10-14 181 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,它工作。

有人提到使用請求是一種更好的方式,我會感激如果有人給我使用請求相同。 謝謝。