Skip to content

Instantly share code, notes, and snippets.

@bashkirtsevich
Created August 2, 2018 10:29
Show Gist options
  • Select an option

  • Save bashkirtsevich/ce10ec1c4bb1cc47523b4c1a6155b97e to your computer and use it in GitHub Desktop.

Select an option

Save bashkirtsevich/ce10ec1c4bb1cc47523b4c1a6155b97e to your computer and use it in GitHub Desktop.
aiohttp json get
import asyncio
import aiohttp
async def http_get_json(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
return await resp.json()
if __name__ == '__main__':
if sys.platform == "win32":
loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
else:
loop = asyncio.get_event_loop()
response = loop.run_until_complete(http_get_json('https://google.com'))
print(response)
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment