Skip to content

Instantly share code, notes, and snippets.

@Tarequzzaman
Last active May 23, 2022 12:46
Show Gist options
  • Save Tarequzzaman/de9aee0eab5b53b8331d6123561d5507 to your computer and use it in GitHub Desktop.
Save Tarequzzaman/de9aee0eab5b53b8331d6123561d5507 to your computer and use it in GitHub Desktop.
Async API call in Python 3
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