skodaconnect / myskoda

Python library for interacting with MySkoda APIs.
MIT License
9 stars 22 forks source link

REST API class stopped working on Windows #90

Closed OBerghmans closed 1 month ago

OBerghmans commented 1 month ago

When running any CLI command I now get the following on Windows.

version: main branch

It seems the self.session connection is closed before the response.text() result is fetched. Seems like this behaviour changed when implementing the "with session" functionality.

poetry run myskoda --user "user" --password "password" --disable-mqtt info vinnumber
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\olivi\AppData\Local\pypoetry\Cache\virtualenvs\myskoda-jII21Bdp-py3.12\Lib\site-packages\asyncclick\core.py", line 1205, in __call__
    return anyio.run(self._main, main, args, kwargs, **opts)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\AppData\Local\pypoetry\Cache\virtualenvs\myskoda-jII21Bdp-py3.12\Lib\site-packages\anyio\_core\_eventloop.py", line 74, in run
    return async_backend.run(func, args, {}, backend_options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\AppData\Local\pypoetry\Cache\virtualenvs\myskoda-jII21Bdp-py3.12\Lib\site-packages\anyio\_backends\_asyncio.py", line 2248, in run
    return runner.run(wrapper())
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\.pyenv\pyenv-win\versions\3.12.2\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\.pyenv\pyenv-win\versions\3.12.2\Lib\asyncio\base_events.py", line 685, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\olivi\AppData\Local\pypoetry\Cache\virtualenvs\myskoda-jII21Bdp-py3.12\Lib\site-packages\anyio\_backends\_asyncio.py", line 2236, in wrapper
    return await func(*args)
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\AppData\Local\pypoetry\Cache\virtualenvs\myskoda-jII21Bdp-py3.12\Lib\site-packages\asyncclick\core.py", line 1208, in _main
    return await main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\AppData\Local\pypoetry\Cache\virtualenvs\myskoda-jII21Bdp-py3.12\Lib\site-packages\asyncclick\core.py", line 1120, in main
    rv = await self.invoke(ctx)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\AppData\Local\pypoetry\Cache\virtualenvs\myskoda-jII21Bdp-py3.12\Lib\site-packages\asyncclick\core.py", line 1739, in invoke
    return await _process_result(await sub_ctx.command.invoke(sub_ctx))
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\AppData\Local\pypoetry\Cache\virtualenvs\myskoda-jII21Bdp-py3.12\Lib\site-packages\asyncclick\core.py", line 1485, in invoke
    return await ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\AppData\Local\pypoetry\Cache\virtualenvs\myskoda-jII21Bdp-py3.12\Lib\site-packages\asyncclick\core.py", line 824, in invoke
    rv = await rv
         ^^^^^^^^
  File "C:\Users\olivi\Local\personal\myskoda\myskoda\cli.py", line 172, in info
    await handle_request(ctx, ctx.obj["myskoda"].get_info, vin)
  File "C:\Users\olivi\Local\personal\myskoda\myskoda\cli.py", line 51, in handle_request
    result = await func(*args)
             ^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\Local\personal\myskoda\myskoda\myskoda.py", line 185, in get_info
    return await self.rest_api.get_info(vin)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\Local\personal\myskoda\myskoda\rest_api.py", line 81, in get_info
    return await self._make_get_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\Local\personal\myskoda\myskoda\rest_api.py", line 58, in _make_get_request
    response_text = await response.text()
                    ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\AppData\Local\pypoetry\Cache\virtualenvs\myskoda-jII21Bdp-py3.12\Lib\site-packages\aiohttp\client_reqrep.py", line 1220, in text
    await self.read()
  File "C:\Users\olivi\AppData\Local\pypoetry\Cache\virtualenvs\myskoda-jII21Bdp-py3.12\Lib\site-packages\aiohttp\client_reqrep.py", line 1178, in read
    self._body = await self.content.read()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olivi\AppData\Local\pypoetry\Cache\virtualenvs\myskoda-jII21Bdp-py3.12\Lib\site-packages\aiohttp\streams.py", line 360, in read
    raise self._exception
aiohttp.client_exceptions.ClientConnectionError: Connection closed
2024-10-11 17:49:50 asyncio[23536] ERROR Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001EBD14D42F0>
2024-10-11 17:49:50 asyncio[23536] ERROR Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x000001EBD2592090>, 124541.718)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x000001EBD2757170>, 124542.734)]']
connector: <aiohttp.connector.TCPConnector object at 0x000001EBCF01CA40>
Prior99 commented 1 month ago

Thanks for the issue and the PR.