Fixing the "Expecting Value" Error with Python Requests

Feb 3, 2024 ยท 2 min read

When making API calls with the Python Requests library, you may occasionally see the error "Expecting value", with a 400 status code. This usually means there was an issue with the request data being sent. Here are some things to try to resolve it:

Ensure Request Data is Formatted Properly

The error often occurs if the data being sent is not formatted as the API expects. For example:

import requests

url = ''
data = {'name': 'John'} 

response =, data)

This sends the data as a regular dict, when the API may expect a JSON string or urlencoded data. Try formatting the data correctly:

import json

data = json.dumps({'name': 'John'})
response =, data=data) 


import requests

data = {'name': 'John'}
response =, data=data)

See the API documentation for details on the expected data format.

Check Required Parameters

Another possibility is that a required parameter is missing from the request. For example, the API may require a user ID or API key. Check the documentation to ensure you are passing all required data.

Handle Empty/Null Values

APIs may also throw this error if you try to pass an empty or null value when a parameter is required. For example:

data = {'name': None}

Would trigger the error since name is expected to have a value. Handle nulls appropriately:

if name is None:
   name = '' 
data = {'name': name}

Use Request Params vs Data Correctly

Another subtle issue is using the params and data parameters incorrectly in the requests call. For example:, params={'name': 'John'})

When the API expects the data in the request body. Always check which parameter should hold the request data.

By properly formatting the request data and handling edge cases like null values, you can avoid this confusing "Expecting Value" error. Pay close attention to the API documentation for exactly how request data should be sent.

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 ""

<!doctype html>
    <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" />


Don't leave just yet!

Enter your email below to claim your free API key: