Reputation: 1
I want to execute a curl with command in python.
Usually, I just need enter the command in terminal and press return key.
The command shows below:
curl -H "`oauth2l header --json key.json mobileinsights`" https://mobileinsights.googleapis.com/v2/networks
The result is in json format.
Upvotes: 0
Views: 2048
Reputation: 179
Use the subprocess
module to run your shell command.
import subprocess
result = subprocess.check_output('curl -H "`oauth2l header --json
key.json mobileinsights`" https://mobileinsights.googleapis.com/v2/networks', shell=True)
Then, use the json
module to parse the JSON data returned by the server.
import json
result_json = json.loads(result)
Upvotes: 1
Reputation: 33
You may load an OS and JSON load modules and then run os.execute(curl URL) store it in any variable then convert it into JSON format with JSON load module
Upvotes: 0