2

I'm a beginner and learning Python. I wanted to write a python code to "call an REST API". Can you please guide me the steps to call an Rest API?

Also I've curl command which I wanted to write it in python code.

curl -u username:password -X GET 'http://google.com:8070/api/v2/organizations'

It would much helpful if anyone can help me out.

Thanks

2 Answers 2

6

The best option for you is possibly using requests package. install it with pip install requests. An exapmple taken from their website is:

r = requests.get('https://api.github.com/user', auth=('user', 'pass'))

For further info check its documentation.

Sign up to request clarification or add additional context in comments.

Comments

-5
import requests
from requests.auth import HTTPBasicAuth

requests.get("http://google.com:8070/api/v2/organizations",auth=HTTPBasicAuth('user', 'pass'))

you should really read some docs and write some code... these things become really obvious with some very quick googling (ie "python http authentication request")

http://docs.python-requests.org/en/master/user/authentication/

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.