0

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.

3
  • Possible duplicate of how to use python to execute a curl command Commented May 9, 2018 at 20:35
  • What's your question? Commented May 9, 2018 at 20:35
  • You could use subprocess to run oauth2l header --json key.json mobileinsights from Python... Then use whatever HTTP library in python to pass a header Commented May 9, 2018 at 20:39

2 Answers 2

1

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) 
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.