sousa-andre / lcu-driver

🐍 Python3 interface for League of Legends Client API
MIT License
113 stars 15 forks source link

The connection seems not ready yet when the function decorated by connector.ready() runs #19

Closed jiyolla closed 2 years ago

jiyolla commented 3 years ago

I'm running a script to launch League Client and some python script to fetch some data from it with the help of lcu-driver(Thank you for your great work and sharing).

This is being done in a cheap remote server, to be specifically, an Azure B1S instance(1vCPU, 1GB RAM).

Probably because of its poor performance(it takes almost 5 mins to finish loading from graphical perspective), even when connecting to it when ready() is fired, it's giving error like this

File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\aiohttp\connector.py", line 969, in _wrap_create_connection return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa File "C:\Users\lstp2021\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 1056, in create_connection raise exceptions[0] File "C:\Users\lstp2021\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 1041, in create_connection sock = await self._connect_sock( File "C:\Users\lstp2021\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 955, in _connect_sock await self.sock_connect(sock, address) File "C:\Users\lstp2021\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 702, in sock_connect return await self._proactor.connect(sock, address) File "C:\Users\lstp2021\AppData\Local\Programs\Python\Python39\lib\asyncio\windows_events.py", line 812, in _poll value = callback(transferred, key, ov) File "C:\Users\lstp2021\AppData\Local\Programs\Python\Python39\lib\asyncio\windows_events.py", line 599, in finish_connect ov.getresult() ConnectionRefusedError: [WinError 1225] The remote computer refused the network connection

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\lstp2021\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\lstp2021\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\lstp2021\Desktop\lolskin-price-tracker\backend\app\update_price_history.py", line 57, in connector.start() File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\lcu_driver\connector.py", line 53, in start wrapper() File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\lcu_driver\connector.py", line 47, in wrapper self.loop.run_until_complete(self.connection.init()) File "C:\Users\lstp2021\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete return future.result() File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\lcu_driver\connection.py", line 70, in init await asyncio.gather(tasks) File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\lcu_driver\events\managers.py", line 27, in run_event await asyncio.create_task( File "C:\Users\lstp2021\Desktop\lolskin-price-tracker\backend\app\update_price_history.py", line 51, in update_skins_price await tqdm_asyncio.gather([update(connection, db, skin) for skin in db.query(models.Skin).all()]) File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\tqdm\asyncio.py", line 79, in gather res = [await f for f in cls.as_completed(ifs, loop=loop, timeout=timeout, File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\tqdm\asyncio.py", line 79, in res = [await f for f in cls.as_completed(ifs, loop=loop, timeout=timeout, File "C:\Users\lstp2021\AppData\Local\Programs\Python\Python39\lib\asyncio\tasks.py", line 614, in _wait_for_one return f.result() # May raise f.exception(). File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\tqdm\asyncio.py", line 76, in wrap_awaitable return i, await f File "C:\Users\lstp2021\Desktop\lolskin-price-tracker\backend\app\update_price_history.py", line 18, in update skin_data = await connection.request('get', skin_api_uri) File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\lcu_driver\connection.py", line 157, in request return await self.session.request(method, url, verify_ssl=False, **kwargs) File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\aiohttp\client.py", line 520, in _request conn = await self._connector.connect( File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\aiohttp\connector.py", line 535, in connect proto = await self._create_connection(req, traces, timeout) File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\aiohttp\connector.py", line 892, in _createconnection , proto = await self._create_direct_connection(req, traces, timeout) File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\aiohttp\connector.py", line 1051, in _create_direct_connection raise last_exc File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\aiohttp\connector.py", line 1020, in _create_direct_connection transp, proto = await self._wrap_create_connection( File "C:\Users\lstp2021\AppData\Local\pypoetry\Cache\virtualenvs\app-k5ozR0H0-py3.9\lib\site-packages\aiohttp\connector.py", line 975, in _wrap_create_connection raise client_error(req.connection_key, exc) from exc aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 127.0.0.1:50763 ssl:False [The remote computer refused the network connection]

I tried to solve this by just waiting for 5mins after the ready() is fired. But it's causing another problem, the connection seems to be timed out so an ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host is raised by CHANCE. Sometimes it works.

I could possibly fix this by using two connectors one just to detect the launch of League Client(by ready()) and sleep 5mins, after that just close and use another connector to my job. Don't know if it will workout.

But I guess ready() is not working as expected(it's not ready yet!). Or is it? So a fix to ready() would help very much. Or maybe I'm miss using the driver, is there anything I should try?

sousa-andre commented 2 years ago

That's odd. The ready event only gets called once the library is able to perform a suceseful GET request to the API as you can see here. This problem is more likely related to the environment where you are trying to run the library in. Can you provide more details about this?

sousa-andre commented 2 years ago

I'm closing this issue for inactivity. Feel free to reopen this if you have anything to add.