I have been writing a Python script to read from a file that contains multiple curl commands and then make HTTP requests to get responses (JSON).
I have done the step of reading the file and saving it to a curl array. Then I'm stuck at the step of using that curl array to make HTTP requests to get responses. Is there any Python library that supports a function that receives a curl string as a parameter and returns an HTTP response?
I have found one solution on StackOverflow is to use "subprocess" to execute the command but its drawback is that it requires "curl" to be installed on the machine which runs the script:
def call_curl(curl):
args = shlex.split(curl)
process = subprocess.Popen(args, shell=False,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
return json.loads(stdout.decode('utf-8'))