Issue
I am trying to execute a curl command in my python script. The curl command executes perfectly in the cmd terminal but for some reason when I try to execute that curl command in python script using os.system() I get an error stating:
'curl' is not recognized as an external or internal command.
Note that curl is already installed in my machine and so it works in cmd terminal. But os.system() also executes in cmd terminal so I am confused why it is not working.
This is my curl command:
curl -u [email protected]:Roboticsengineering1@ai https://confluence.ai.com/rest/api/content/494966599?expand=body.storage | python -mjson.tool > confluence_output.json
This is my code:
import os
import sys
execute_statement = 'curl -u [email protected]:Roboticsengineering1@ai https://confluence.ai.com/rest/api/content/494966599?expand=body.storage | python -mjson.tool > confluence_output.json'
exit_code = os.system(execute_statement)
if exit_code != 0:
sys.exit(1)
Solution
Instead of executing curl command I used the python requests to gather my data for parsing.
import requests
from requests.auth import HTTPBasicAuth
# Making a get request
response = requests.get('https://confluence.ai.com/rest/api/content/494966599?expand=body.storage',
auth=HTTPBasicAuth('[email protected]', 'Roboticsengineering1@ai')).json()
# print request object
print(response)
Answered By - Ashish Answer Checked By - Cary Denson (WPSolving Admin)