HTTP Library in Python
HTTP Library in Python
The most commonly used library to handle HTTP requests is requests. It’s a simple yet powerful library for making HTTP requests to interact with APIs and websites.
Install the requests library
If you don’t have it installed, you can install it via pip:
$ pip install requests
Making Basic HTTP Requests
The basic usage of the requests library to issue a GET Request is as follows:
Fetching data from a URL.
import requests
response = requests.get('https://api.example.com/data')
if response.status_code == 200:
print(response.json()) # Parse JSON data
else:
print(f"Failed to retrieve data: {response.status_code}")