Created
February 5, 2019 21:38
-
-
Save ykshatroff/a3eac1f6224bf3659267e17b9ff93bc1 to your computer and use it in GitHub Desktop.
Aiohttp error in getaddrinfo()
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 aiohttp | |
import asyncio | |
async def request(session, url): | |
try: | |
async with session.get(url) as resp: | |
pass | |
except: | |
# raises: TypeError: getaddrinfo() argument 1 must be string or None | |
# after a couple of requests to different hosts | |
import pdb; pdb.post_mortem() | |
raise SystemExit | |
async def testit(loop): | |
connector = aiohttp.TCPConnector(limit=17, limit_per_host=19, resolver=aiohttp.AsyncResolver(), use_dns_cache=False) | |
# session = aiohttp.ClientSession(loop=loop) | |
session = aiohttp.ClientSession(loop=loop, connector=connector) | |
await asyncio.gather(*[ | |
request(session, url) | |
for _ in range(20) | |
for url in ('https://www.facebook.com', 'https://vk.com', 'https://google.com') | |
]) | |
if __name__ == '__main__': | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(testit(loop)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment