I'm trying to pass a date in post request with aiohttp:
import asyncio
import json
from datetime import datetime
from pprint import pprint
import aiohttp
payload = {'key1': 'value1', 'key2': 'value2', 'now': datetime.now()}
async def main():
async with aiohttp.ClientSession() as session:
async with session.post('http://httpbin.org/post', json=payload) as resp:
pprint(await resp.json())
asyncio.run(main())
But all I get is error:
TypeError: Object of type datetime is not JSON serializable
How to fix it?
P.S. I already tried json.dumps.
P.P.S. Please don't offer convert now
to string. The example above is simplified example.