-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Describe the bug
When i have form encoded data with None, by using requests the data is not sent to the server. But this is different for aiohttp, is sent "None" string. This happen also in httpx, take a look at this issue encode/httpx#1500. Is this really the expected behavior?
To Reproduce
Code
import asyncio
from aiohttp import ClientSession
async def main():
async with ClientSession() as session:
async with session.post("https://httpbin.org/post", data={"foo": None}) as resp:
print(await resp.json())
asyncio.run(main())Output
{'args': {}, 'data': '', 'files': {}, 'form': {'foo': 'None'}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Content-Length': '8', 'Content-Type': 'application/x-www-form-urlencoded', 'Host': 'httpbin.org', 'User-Agent': 'Python/3.12 aiohttp/3.9.1', 'X-Amzn-Trace-Id': 'Root=1-65ae0f19-5b556c225f8d6df5174e435d'}, 'json': None, 'origin': '110.137.36.152', 'url': 'https://httpbin.org/post'}
Take a look at the form, its contain None 'form': {'foo': 'None'}.
Expected behavior
Code
import requests
resp = requests.post("https://httpbin.org/post", data={"foo": None})
print(resp.json())Output
{'args': {}, 'data': '', 'files': {}, 'form': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Content-Type': 'application/x-www-form-urlencoded', 'Host': 'httpbin.org', 'Transfer-Encoding': 'chunked', 'User-Agent': 'python-requests/2.31.0', 'X-Amzn-Trace-Id': 'Root=1-65ae0f4c-569162ab7ff3089468c91391'}, 'json': None, 'origin': '110.137.36.152', 'url': 'https://httpbin.org/post'}
Take a look at the form, its empty 'form': {}.
Logs/tracebacks
N/APython Version
Python 3.12.1aiohttp Version
name : aiohttp
version : 3.9.1
description : Async http client/server framework (asyncio)multidict Version
name : multidict
version : 6.0.4
description : multidict implementationyarl Version
name : yarl
version : 1.9.4
description : Yet another URL libraryOS
Windows 10
Related component
Client
Additional context
No response
Code of Conduct
- I agree to follow the aio-libs Code of Conduct
Reactions are currently unavailable