Closed becjacky closed 3 years ago
I guess you are using a Jupyter notebook or something like that?
If so, then try this:
import nest_asyncio
nest_asyncio.apply()
Sorry for not specifying my working console! I'm running the code in Jupyter notebook on windows system indeed! Now I change the code but get an empty list:
import nest_asyncio
import json
import aiohttp
from understat import Understat
nest_asyncio.apply()
async def main():
async with aiohttp.ClientSession() as session:
understat = Understat(session)
fixtures = await understat.get_league_fixtures(
"epl",
2018,
{
"h": {"id": "89",
"title": "Manchester United",
"short_title": "MUN"}
}
)
print(json.dumps(fixtures))
loop1 = asyncio.get_event_loop()
loop1.run_until_complete(main())
I don't know where the problem come from. :D
Try removing the options ({"h": {"id": "89", "title": "Manchester United", "short_title": "MUN"}}
) and see if it returns anything.
Thanks for response! After removing the block you mentioned above, I still got an empty list. Upset!
Sorry for the late reply, I thought I had already replied. Fixtures are matches yet to be played (2018 season is in the past), so you should use get_league_results
instead.
I got a run time error which is : This event loop is already running.
My code is:
`async def main(): async with aiohttp.ClientSession() as session: understat = Understat(session) results = await understat.get_team_results( "Levante", 2019, side="a" ) print(json.dumps(results))
if name == "main": loop = asyncio.get_event_loop() loop.run_until_complete(main())`