【问题标题】:Execute curl command and fetch response执行 curl 命令并获取响应
【发布时间】:2021-04-28 03:29:05
【问题描述】:

我有一个 curl 命令。我想在 python 3 中执行后获取响应。

curl https://api.abc.com/targets/targetID\ 
-X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: JWT PROBELY_AUTH_TOKEN"

如何在 Python 中执行脚本并获得响应?

【问题讨论】:

标签: python curl libcurl pycurl


【解决方案1】:

试试这个:

import requests

url = 'https://api.abc.com/targets/AxthamE0v3E-/scans/S6dOMPj8SsoH/'
r = requests.get(url,headers={"Content-Type": "application/json","Authorization": "JWT PROBELY_AUTH_TOKEN"})
print(r.text)

【讨论】:

    【解决方案2】:

    如果您需要执行请求,可以使用库requests。 您可以使用pip install requests 轻松安装它

    https://www.w3schools.com/python/module_requests.asp 您可以使用此链接查看如何使用此库

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-14
      • 2015-10-07
      • 1970-01-01
      • 1970-01-01
      • 2014-10-08
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      相关资源
      最近更新 更多