From this tutorial for multiple asynchronous get requests I copied and ran the following code:
import asyncio import aiohttp def fetch_page(url, idx): url = 'https://yahoo.com' response = yield from aiohttp.request('GET', url) if response.status == 200: print("data fetched successfully for: %d" % idx) else: print("data fetch failed for: %d" % idx) print(response.content, response.status) def main(): url = 'https://yahoo.com' urls = [url] * 100 coros = [] for idx, url in enumerate(urls): coros.append(asyncio.Task(fetch_page(url, idx))) yield from asyncio.gather(*coros) if __name__ == '__main__': loop = asyncio.get_event_loop() loop.run_until_complete(main()) However, I get the following errors:
RuntimeWarning: coroutine 'ClientSession._request' was never awaited
Unclosed client session TypeError: '_SessionRequestContextManager'
https://stackoverflow.com/questions/65930078/typeerror-sessionrequestcontextmanager-object-is-not-iterable January 28, 2021 at 10:12AMTypeError: '_SessionRequestContextManager' object is not iterable
没有评论:
发表评论