-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Open
Description
Both an empty string '' and an empty list [] are not of NoneType and are considered a falsy value and therefore should behave the same when being added as a URL parameter. But in requests when passing an empty string '' as a parameter value the final URL contains the parameter but not when an empty list [] is passed as the value.
Expected Result
When passing an empty list as parameter value, the final URL should contain the parameter.
Actual Result
When passing an empty list as parameter value, the final URL does not contain the parameter.
Reproduction Steps
import requests
base_url = 'https://jsonplaceholder.typicode.com/todos'
params = {'_limit': 5, 'id__in': ''}
response = requests.get(base_url, params)
print(response.request.url)
# Output: https://jsonplaceholder.typicode.com/todos?_limit=5&id__in=
params = {'_limit': 5, 'id__in': []}
response = requests.get(base_url, params)
print(response.request.url)
# Output: https://jsonplaceholder.typicode.com/todos?_limit=5System Information
$ python -m requests.help
{
"chardet": {
"version": null
},
"charset_normalizer": {
"version": "3.1.0"
},
"cryptography": {
"version": ""
},
"idna": {
"version": "3.4"
},
"implementation": {
"name": "CPython",
"version": "3.10.11"
},
"platform": {
"release": "22.6.0",
"system": "Darwin"
},
"pyOpenSSL": {
"openssl_version": "",
"version": null
},
"requests": {
"version": "2.28.2"
},
"system_ssl": {
"version": "1010115f"
},
"urllib3": {
"version": "1.26.15"
},
"using_charset_normalizer": true,
"using_pyopenssl": falseKrupakar-Reddy-S
Metadata
Metadata
Assignees
Labels
No labels