试图减少时间或同时提出要求

trying to reduce the time or make requests at the same time

我可以同时提出所有这些请求吗?我正在努力减少时间...

def pokemons():
    
    for i in range(1, 800):
        url = f"https://pokeapi.co/api/v2/pokemon/{i}"
        requisicao = requests.get(url)

        try:
            lista = requisicao.json()
        except ValueError:
            print("ERRO TIPO")

你要的是AIOHTTPAsynchronous HTTP Client/Server.

import asyncio
import aiohttp
import ssl


async def fetch(session, pokemon_num):
    url = f"https://pokeapi.co/api/v2/pokemon/{pokemon_num}"
    async with session.get(url, ssl=ssl.SSLContext()) as response:
        return await response.json()


async def fetch_all(loop):
    async with aiohttp.ClientSession(loop=loop) as session:
        results = await asyncio.gather(*[fetch(session, pokemon_n) for pokemon_n in range(800)], return_exceptions=True)
        return results


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    result = loop.run_until_complete(fetch_all(loop))
    print(result)

我 运行 这段代码并在总共 19.5 秒内获得了所有请求。希望对你有帮助。

以上片段来自的另一个回答,如果觉得合适,可以给他点个赞。我根据您的具体参数进行了调整。

祝大家好运!