在python脚本中运行curl命令而不返回

时间:2018-03-22 07:07:54

标签: python python-2.7

我有如下curl命令和预期结果如下:

[root@10 master]# curl -X GET -u 'admin:password' https://22.11.xx.1/api/1.0/reports/id/78/?csv_format=xls --insecure
Output:
        {"file_url": "/var/www/graphics/images/temp/report365828.xlsx"}
[root@10 master]

我有脚本:

import subprocess
command = 'curl -X GET -u "admin:password" https://22.11.xx.1/api/1.0/reports/id/1/?csv_format=xls --insecure'
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()

但我在这里没有得到任何输出,我有什么遗漏吗?

2 个答案:

答案 0 :(得分:0)

command = 'curl -X GET -u "admin:password" https://22.11.xx.1/api/1.0/reports/id/1/?csv_format=xls --insecure'

将其转换为命令列表

['curl',
 '-X',
 'GET',
 '-u',
 '"admin:password"',
 'https://22.11.xx.1/api/1.0/reports/id/1/?csv_format=xls',
 '--insecure']

答案 1 :(得分:-1)

     import os
     command = """your command"""
     result = os.popen(command).read()
     print(result)