make a http request with url parameters in python

To make an HTTP request with URL parameters in Python, you can use the popular requests library. You need to include the parameters as a dictionary object in the params parameter of the requests.get() function.

Here's a code snippet that demonstrates how to make an HTTP GET request with URL parameters in Python using the requests library:

main.py
import requests

url = 'https://example.com/api'
params = {'param1': 'value1', 'param2': 'value2'}

response = requests.get(url, params=params)

print(response.text)
166 chars
9 lines

In this code, we're making an HTTP GET request to the URL https://example.com/api with two URL parameters: param1 and param2. The requests.get() function includes the parameters in the URL automatically.

You can also use the params parameter with other HTTP methods like POST, PUT, and DELETE. Just modify the requests.get() function accordingly.

gistlibby LogSnag