My python 3 code gives unwanted response instead of the required response

  aiohttp, python-3.x, python-asyncio

A friend of mine has made this code

THE CODE IS

Credits: TERMINATOR

import aiohttp
import asyncio


async def get_response(query):
    async with aiohttp.ClientSession() as ses:
        async with ses.get(
            f'https://some-random-api.ml/chatbot?message={query}'
        ) as resp:
            return (await resp.json()),['response']
    
#using an event loop
loop = asyncio.get_event_loop()
Task = asyncio.gather(*[get_response('world') for _ in range(500)])

try:
    loop.run_until_complete(Task)
finally:
    loop.close()

BUT IT RETURN RESPONSE LIKE

({'response': "What's up?"}, ['response'])

Can you modify code in such a way that it returns only the response like What’s up?

And if error it responses the error like too many requests

Source: Python-3x Questions

LEAVE A COMMENT