I was using asyncio to send multiple API requests at once and it worked totally fine in the code I wrote for a different site but now when it gets to the asyncio.gather() function the program stays in it infinitely. I have checked if the parameters are good just using basic requests and it returns everything normally.
games = ['2498966115', '2498966220', '2498966394', '2498966397', '2498966145', '2498966223', '2498966361', '2498966364', '2498966367', '2498966373', '2498966382', '2498967870', '2498966385', '2498966118', '2498966376', '2498966379', '2498966073', '2498953515', '2498953518']
headers1 = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0",
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "",
"Origin": "https://sports-sm-web.7platform.net",
"DNT": "1",
"Sec-GPC": "1",
"Connection": "keep-alive",
"Referer": "https://sports-sm-web.7platform.net/?companyId=4f54c6aa-82a9-475d-bf0e-dc02ded89225&lang=sr-Latn&auth=b2b&gateway=true&companyName=balkanbet&integrationType=gravityGateway&platform=seven&application=web§ion=1-offer&sport=18-fudbal",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "cross-site",
"If-None-Match": "W/31271-j+rArRqx3e06gJ2zOQGV7w",
"TE": "trailers"
}
results=[]
def get_tasks(session):
tasks =[]
for id in games:
url1 = "https://sports-sm-distribution-api.de-2.nsoftcdn.com/api/v1/events/"+str(id)
querystring1 = {"companyUuid":"4f54c6aa-82a9-475d-bf0e-dc02ded89225","id":str(id),"language":"^%^7B^%^22default^%^22:^%^22sr-Latn^%^22,^%^22events^%^22:^%^22sr-Latn^%^22,^%^22sport^%^22:^%^22sr-Latn^%^22,^%^22category^%^22:^%^22sr-Latn^%^22,^%^22tournament^%^22:^%^22sr-Latn^%^22,^%^22team^%^22:^%^22sr-Latn^%^22,^%^22market^%^22:^%^22sr-Latn^%^22^%^7D","timezone":"Europe^%^2FBudapest","dataFormat":"{"default":"array","markets":"array","events":"array"}"}
tasks.append(session.get(url1,headers=headers1, params=querystring1))
return tasks
async def matches():
tasks = []
session = aiohttp.ClientSession()
tasks = get_tasks(session)
responses = await asyncio.gather(*tasks)
for response in responses:
results.append(await response.json())
await session.close()
return results
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
results = loop.run_until_complete(matches())
loop.close()
print(results)