amosbastian / understat

An asynchronous Python package for https://understat.com/.
MIT License
150 stars 29 forks source link

run time error #15

Closed becjacky closed 3 years ago

becjacky commented 3 years ago

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())`

amosbastian commented 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()
becjacky commented 3 years ago

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

amosbastian commented 3 years ago

Try removing the options ({"h": {"id": "89", "title": "Manchester United", "short_title": "MUN"}}) and see if it returns anything.

becjacky commented 3 years ago

Thanks for response! After removing the block you mentioned above, I still got an empty list. Upset!

amosbastian commented 3 years ago

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.