简体   繁体   English

无法解析主机:>

[英]Could not resolve host: >

I am trying to issue a curl command from python, from command line it works fine : 我正在尝试从python发出curl命令,从命令行可以正常工作:

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

but when I called it from python : 但是当我从python调用它时:

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:H@ror1987 https://" +addresses[argv[2]].strip()+ ":5550/service/mgmt/current > Response\generated_Resp.xml"
print(command)
p = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]

I got : Could not resolve host: > 我得到了:无法解析主机:>

with the help of swstephe , added shell=True, it worked. 在swstephe的帮助下,添加shell = True可以正常工作。

someone mentioned using Requests is a better way, I will appreciated if someone gave me the same using Requests. 有人提到使用请求是一种更好的方法,如果有人使用请求给了我相同的信息,我将不胜感激。 Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM