spacemanspiff2007 / HABApp

Easy home automation with MQTT and/or openHAB
Apache License 2.0
54 stars 23 forks source link

TypeError: aiohttp.client.ClientSession._request() got multiple values for keyword argument 'params' #424

Closed ntzagkarakiswings closed 7 months ago

ntzagkarakiswings commented 8 months ago

Hello @spacemanspiff2007,

I recently updated to the latest version (23.09.2) and I'm getting an error when trying to use the async_set_persistence_data method. TypeError: aiohttp.client.ClientSession._request() got multiple values for keyword argument 'params'

After digging into your code at/HABApp/openhab/connection/handler/handler.py, I noticed that all calls to self.request have the argument **kwargstwice. When I removed the one, async_set_persistence_data worked without any errors.

Bellow are the logs describing the error:

[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR | File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/connection/handler/func_async.py", line 398 in async_set_persistence_data
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR | --------------------------------------------------------------------------------
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |      382 | async def async_set_persistence_data(item: str | ItemRegistryItem, persistence: str | None,
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |      383 |                                      time: datetime, state: Any):
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |      384 |     # noinspection PyProtectedMember
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |        (...)
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |      391 |     params = {
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |      392 |         'time': convert_to_oh_type(time),
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |      393 |         'state': convert_to_oh_type(state),
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |      394 |     }
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |      395 |     if persistence is not None:
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |      396 |         params['serviceId'] = persistence
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR | -->  398 |     ret = await put(f'/rest/persistence/items/{item:s}', params=params)
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |      399 |     if ret.status >= 300:
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |    ------------------------------------------------------------
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |      item = 'testItem'
[2023-10-31 16:22:34,707] [            HABApp.Worker]    ERROR |      params = {'time': '2023-10-31T15:49:58.219649+0000', 'state': '0.62', 'serviceId': 'jdbc'}
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      params['serviceId'] = 'jdbc'
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      persistence = 'jdbc'
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      state = 0.62
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      time = datetime.datetime(2023, 10, 31, 15, 49, 58, 219649)
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      persistence is not None = True
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |    ------------------------------------------------------------
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR | File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/connection/handler/handler.py", line 108 in put
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR | --------------------------------------------------------------------------------
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      103 | async def put(self, url: str, log_404=True, json=None, data=None, **kwargs: Any) -> ClientResponse | None:
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      104 |     if self.read_only or not self.online:
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      105 |         return None
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      107 |     mgr = _RequestContextManager(
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR | -->  108 |         self.request(METH_PUT, url, data=data, json=json, **kwargs, **self.options, **kwargs)
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      109 |     )
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      110 |     if data is None:
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |    ------------------------------------------------------------
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      _RequestContextManager = <class 'aiohttp.client._RequestContextManager'>
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      not self.online = False
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      self = <HABApp.openhab.connection.handler.handler.ConnectionHandler object at 0x7fb98bbcfac0>
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      self.online = True
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      self.options = {}
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      self.read_only = False
[2023-10-31 16:22:34,708] [            HABApp.Worker]    ERROR |      self.read_only or not self.online = False
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |      self.request = <bound method ClientSession._request of <aiohttp.client.ClientSession object at 0x7fb98b93aef0>>
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |      data = None
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |      json = None
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |      kwargs = {'params': {'time': '2023-10-31T15:49:58.219649+0000', 'state': '0.62', 'serviceId': 'jdbc'}}
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |      log_404 = True
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |      METH_PUT = 'PUT'
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |      url = '/rest/persistence/items/testItem'
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |    ------------------------------------------------------------
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR | --------------------------------------------------------------------------------
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR | Traceback (most recent call last):
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |   File "/usr/local/lib/python3.10/site-packages/HABApp/core/internals/wrapped_function/wrapped_async.py", line 30, in async_run
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |     await self.func(*args, **kwargs)
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |   File "/app/HABApp/rules/update_states.py", line 81, in update_state
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |     await store(item=oh_item, state=state, timestamp=timestamp)
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |   File "/app/HABApp/custom_modules/habapp_utils/store.py", line 49, in store
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |     await async_set_persistence_data(
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |   File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/connection/handler/func_async.py", line 398, in async_set_persistence_data
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |     ret = await put(f'/rest/persistence/items/{item:s}', params=params)
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |   File "/usr/local/lib/python3.10/site-packages/HABApp/openhab/connection/handler/handler.py", line 108, in put
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR |     self.request(METH_PUT, url, data=data, json=json, **kwargs, **self.options, **kwargs)
[2023-10-31 16:22:34,709] [            HABApp.Worker]    ERROR | TypeError: aiohttp.client.ClientSession._request() got multiple values for keyword argument 'params'

I can make a merge request if you want, but it seems it is just a typo. Thank you in advance.

spacemanspiff2007 commented 8 months ago

Thank you for your report. I'll fix this next week since I'll have to add a test, too. You can just patch this locally (just edit the file) so you can continue using the latest version.