Created
August 2, 2018 10:29
-
-
Save bashkirtsevich/ce10ec1c4bb1cc47523b4c1a6155b97e to your computer and use it in GitHub Desktop.
aiohttp json get
This file contains hidden or 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 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