Last active
May 23, 2022 12:46
-
-
Save Tarequzzaman/de9aee0eab5b53b8331d6123561d5507 to your computer and use it in GitHub Desktop.
Async API call in Python 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import aiohttp | |
url = "http://127.0.0.1:5005/webhooks/rest/webhook" | |
data = '{"sender":"218311","message":"english"}' | |
async def aiohttp_session(): | |
async with aiohttp.ClientSession() as session: | |
async with session.post(url, data=data) as r: | |
return await r.json() if r.status ==200 else await r.text | |
try: | |
d = await aiohttp_session() | |
print(d) | |
except Exception as e: | |
print(str(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment