从python脚本调用curl

时间:2016-06-28 15:33:57

标签: python api powershell curl

我正在尝试使用curl连接到Splunk API并运行搜索并将结果存储到.csv文件中。我可以使用subprocess模块和powershell.exe进行此操作,如下面的代码块所示

powershell_path = "C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
search_string = '<search to be used>'
curl_command = '\ncurl -k -u <other args>'
subprocess.call([powershell_path, search_string, curl_command])

但是,我希望能够在不使用powershell.exe的情况下执行此操作。我尝试用powershell.exe的路径替换路径curl.exe,然后我收到错误,告诉我我的search_stringcurl_command变量中有非法字符(使用\帮助逃避他们,当我尝试直接使用subprocess.call中的路径时:

subprocess.call(['<path to curl.exe>', '<full search string>, 'curl -k -u <other args>'])

我收到错误WindowsError: [Error 2] The system cannot find the file specified(我检查了文件路径并尝试os.join,无处可去)。如何在Python中使用curl连接到Splunk API,运行搜索,将结果保存到csv,并在不调用Powershell等外部应用程序的情况下完成所有这些操作?

0 个答案:

没有答案