Search code examples
pythoncurllibcurlpycurl

Execute curl command and fetch response


I have a curl command. I want to fetch the response after executing it in python 3.

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

How can I execute the script in Python and get the response ?


Solution

  • try this:

    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)