When making HTTP requests in Python, you may not always need to use a proxy. The popular requests library provides a simple way to make requests directly without configuring a proxy.
Why Make Requests Without a Proxy
Some reasons you may want to make requests without a proxy:
In these cases, the
Making Simple GET Requests
Here is how to make a basic GET request without a proxy using
import requests
response = requests.get('https://api.example.com/items')
print(response.status_code)
print(response.json())
We simply call
Customizing the Requests
Additional headers, URL parameters, data, and other options can be specified to customize requests:
import requests
headers = {'Authorization': 'token1234'}
params = {'category': 'electronics'}
response = requests.get('https://api.example.com/items',
headers=headers, params=params)
This adds an authorization header and category parameter to the request.
Handling Timeouts
You can tell requests to timeout if an API is slow to respond:
requests.get('https://api.example.com/slow', timeout=3.0)
This will error after 3 seconds if no response.
So in summary, the