Skip to content

Instantly share code, notes, and snippets.

@ykshatroff
Created February 5, 2019 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykshatroff/a3eac1f6224bf3659267e17b9ff93bc1 to your computer and use it in GitHub Desktop.
Save ykshatroff/a3eac1f6224bf3659267e17b9ff93bc1 to your computer and use it in GitHub Desktop.
Aiohttp error in getaddrinfo()
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