Sending Data in GET Requests with Python Requests

Feb 3, 2024 ยท 2 min read

The Python Requests library provides a simple way to send GET requests with data using the requests.get() method.

Here is an example GET request that sends some data to a URL:

import requests

url = 'https://api.example.com/data'

payload = {'key1': 'value1', 'key2': 'value2'}
response = requests.get(url, params=payload)

print(response.url)
# https://api.example.com/data?key1=value1&key2=value2

As you can see, we pass a dictionary payload to the params parameter of requests.get(). This dictionary contains the key-value pairs of data we want to send.

Requests encodes this dictionary into a query string that is appended to the URL. You can see the full URL with the query string printed out.

This is perfect for sending non-sensitive data like filters, pagination options, etc. in a GET request. The data shows up right in the URL.

Some tips when sending data in GET requests:

  • Don't send large payloads of data to avoid hitting URL length limits
  • Encode any spaces, slashes, etc to avoid issues (Requests does this encoding automatically)
  • Consider using POST requests for sensitive data or very large payloads
  • Example fetching paginated data:

    params = {'page': 2, 'per_page': 25}  
    response = requests.get(url, params=params)

    Here we fetch page 2 with 25 results per page. The page and per_page options are sent right in the URL parameter.

    So in summary, Requests makes it very easy to send additional data in your GET requests using a params dictionary. Give it a try next time you need to send filters or options!

    Browse by tags:

    Browse by language:

    The easiest way to do Web Scraping

    Get HTML from any page with a simple API call. We handle proxy rotation, browser identities, automatic retries, CAPTCHAs, JavaScript rendering, etc automatically for you


    Try ProxiesAPI for free

    curl "http://api.proxiesapi.com/?key=API_KEY&url=https://example.com"

    <!doctype html>
    <html>
    <head>
        <title>Example Domain</title>
        <meta charset="utf-8" />
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
    ...

    X

    Don't leave just yet!

    Enter your email below to claim your free API key: