sousa-andre / lcu-driver

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

Request returns _RequestContextManager instead of ClientResponse #29

Closed LeagueOfPoro closed 1 year ago

LeagueOfPoro commented 1 year ago

Hi, it seems like the connection.request is returning _RequestContextManager instead of the proper ClientResponse.

I'm testing it on the example code from docs:

from lcu_driver import Connector

connector = Connector()

@connector.ready
async def connect(connection):
    summoner = await connection.request('get', '/lol-summoner/v1/current-summoner')
    print(await summoner.json())

connector.start()

Throws:

Traceback (most recent call last):
  File "C:\MyProjects\PoroLobby\test.py", line 11, in <module>
    connector.start()
  File "c:\users\pc\.virtualenvs\porolobby-tdh_zplj\src\lcu-driver\lcu_driver\connector.py", line 70, in start
    wrapper()
  File "c:\users\pc\.virtualenvs\porolobby-tdh_zplj\src\lcu-driver\lcu_driver\connector.py", line 64, in wrapper
    self.loop.run_until_complete(connection.init())
  File "C:\Users\PC\.pyenv\pyenv-win\versions\3.10.6\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "c:\users\pc\.virtualenvs\porolobby-tdh_zplj\src\lcu-driver\lcu_driver\connection.py", line 78, in init
    await asyncio.gather(*tasks)
  File "c:\users\pc\.virtualenvs\porolobby-tdh_zplj\src\lcu-driver\lcu_driver\events\managers.py", line 30, in run_event
    await asyncio.create_task(
  File "C:\MyProjects\PoroLobby\test.py", line 9, in connect
    print(await summoner.json())
AttributeError: '_RequestContextManager' object has no attribute 'json'
sys:1: RuntimeWarning: coroutine 'ClientSession._request' was never awaited
Exception ignored in: <function LoopSensitiveManager.__del__ at 0x00000283E2E3DFC0>
Traceback (most recent call last):
  File "c:\users\pc\.virtualenvs\porolobby-tdh_zplj\src\lcu-driver\lcu_driver\loop.py", line 47, in __del__
  File "C:\Users\PC\.pyenv\pyenv-win\versions\3.10.6\lib\asyncio\runners.py", line 39, in run
  File "C:\Users\PC\.pyenv\pyenv-win\versions\3.10.6\lib\asyncio\events.py", line 782, in new_event_loop
  File "C:\Users\PC\.pyenv\pyenv-win\versions\3.10.6\lib\asyncio\events.py", line 673, in new_event_loop
  File "C:\Users\PC\.pyenv\pyenv-win\versions\3.10.6\lib\asyncio\windows_events.py", line 315, in __init__
  File "C:\Users\PC\.pyenv\pyenv-win\versions\3.10.6\lib\asyncio\proactor_events.py", line 635, in __init__
ImportError: sys.meta_path is None, Python is likely shutting down
sys:1: RuntimeWarning: coroutine 'LoopSensitiveManager.cull' was never awaited
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x00000283E2E66320>

I am using the latest lcu-driver from github. Pipfile:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
lcu-driver = {editable = true, git = "https://github.com/sousa-andre/lcu-driver.git"}

[dev-packages]

[requires]
python_version = "3.10"
Avnsx commented 1 year ago

I mentioned this too 5 months ago and he released a beta version: https://github.com/sousa-andre/lcu-driver/tree/3.0.0a2

Didn't try it out yet though, finding that bug in his code after 400 lines of implementing it like that, tilted me too much back then. Still trying to get back into it πŸ˜… Let me know if you figure out how it works

LeagueOfPoro commented 1 year ago

@Avnsx TBH, I am just dropping lcu-driver in my project. I need only simple HTTPS communication anyway and this whole library is a bit overkill.

sousa-andre commented 1 year ago

@LeagueOfPoro The issue should be fixed with the latest commit (65bf219). The library was broken by a pull request I merged a year ago that I forgot to fix until now πŸ˜…

sousa-andre commented 1 year ago

@Avnsx TBH, I am just dropping lcu-driver in my project. I need only simple HTTPS communication anyway and this whole library is a bit overkill.

Why do you believe the library is a overkill? Any ideas how I could make it better/simpler?

LeagueOfPoro commented 1 year ago

I'm glad you figured it out.

The library is great. πŸ™‚ But all I need is to send simple nonasync get/post. So managing a dependency is not worth for me when the entire code I need is only 40 LOC

sousa-andre commented 1 year ago

I'm glad you figured it out.

The library is great. πŸ™‚ But all I need is to send simple nonasync get/post. So managing a dependency is not worth for me when the entire code I need is only 40 LOC

Understandable πŸ‘πŸΌ

sousa-andre commented 1 year ago

I'm closing this issue since the problem should be fixed.