Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix throwing KeyError: 'presence' Python errors #52959

Closed
Reforest4635 opened this issue Jul 13, 2021 · 13 comments · Fixed by #53508
Closed

Matrix throwing KeyError: 'presence' Python errors #52959

Reforest4635 opened this issue Jul 13, 2021 · 13 comments · Fixed by #53508

Comments

@Reforest4635
Copy link

The problem

After the recent update I have had signs python errors pop up. I have not added to or changed my configuration. This just started the past week so I think it was the 2021.07.1 update. I tried updating to 2021.7.2 hoping there was a fix. Both integrations matrix,rainbird were working before the update but now cause errors.

What is version of Home Assistant Core has the issue?

2021.7.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Rainbird, matrix

Link to integration documentation on our website

https://www.home-assistant.io/integrations/matrix

Example YAML snippet

No response

Anything in the logs that might be useful for us?

With rainbird in configuration I cannot restart home assistant I get this error. Rainbird did work before.

__init__() got an unexpected keyword argument 'encoding

Matrix error 

Logger: homeassistant.setup
Source: components/matrix/__init__.py:341
First occurred: 5:02:53 AM (1 occurrences)
Last logged: 5:02:53 AM

Error during setup of component matrix
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 249, in _async_setup_component
    result = await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/matrix/__init__.py", line 88, in setup
    bot = MatrixBot(
  File "/usr/src/homeassistant/homeassistant/components/matrix/__init__.py", line 169, in __init__
    self._client = self._login()
  File "/usr/src/homeassistant/homeassistant/components/matrix/__init__.py", line 312, in _login
    client = self._login_by_password()
  File "/usr/src/homeassistant/homeassistant/components/matrix/__init__.py", line 341, in _login_by_password
_client.login_with_password(self._mx_id, self._password)
  File "/usr/local/lib/python3.9/site-packages/matrix_client/client.py", line 249, in login_with_password
    return self.login(username, password, limit, sync=True)
  File "/usr/local/lib/python3.9/site-packages/matrix_client/client.py", line 280, in login
    self._sync()
  File "/usr/local/lib/python3.9/site-packages/matrix_client/client.py", line 558, in _sync
    for presence_update in response['presence']['events']:
KeyError: 'presence'

Additional information

No response

@probot-home-assistant
Copy link

matrix documentation
matrix source
(message by IssueLinks)

@probot-home-assistant
Copy link

Hey there @tinloaf, mind taking a look at this issue as its been labeled with an integration (matrix) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@DanNixon
Copy link
Contributor

DanNixon commented Jul 13, 2021

Regarding Matrix, this seems to be an issue in the upstream library. See matrix-org/matrix-python-sdk#320.

@Salamandar
Copy link

Bug is present on my instance as well.

@tophers
Copy link

tophers commented Jul 17, 2021

Same bug, nothing has changed with my Matrix config in HomeAssistant, I didn't notice any breaking changes around this component but this didn't happen after a Home Assistant update either. Currently running Core 2021.7.3, I've restored back to 2021.6.1 and the Matrix component will not start on any version. Same error different keyerror in my logs 'invite'.

@DanNixon
Copy link
Contributor

Given that https://github.com/matrix-org/matrix-python-sdk looks to be abandonware at this point, the integration should probably be rewritten to use https://github.com/poljar/matrix-nio.

This is an actively updated library where issues like this would likely be solved with a version bump and would also allow such niceties as end-to-end encryption.

@surakin
Copy link

surakin commented Jul 18, 2021

This was probably caused by the smaller sync responses introduced in synapse 1.38
I made a small PR that seems to fix it matrix-org/matrix-python-sdk#321

@tophers
Copy link

tophers commented Jul 18, 2021

This was probably caused by the smaller sync responses introduced in synapse 1.38
I made a small PR that seems to fix it matrix-org/matrix-python-sdk#321

Thanks for that pull, and the issue started after a Synapse update, so it makes sense.
I did run into a different issue using the client.py changes in that pull.

*edit - My issue was a version difference with what was on github, thanks for that PR.

@frenck frenck changed the title Python errors Matrix throwing KeyError: 'presence' Python errors Jul 19, 2021
@Ulrar
Copy link

Ulrar commented Jul 21, 2021

I'm getting the same but with 'Invite' as the key, assuming this is the same issue.
Is there an easy way to use that PR in a container, to fix the issue manually while we wait for upstream to merge ?

@surakin
Copy link

surakin commented Jul 21, 2021

I'm getting the same but with 'Invite' as the key, assuming this is the same issue.
Is there an easy way to use that PR in a container, to fix the issue manually while we wait for upstream to merge ?

If you are using the docker image, yes.

https://docs.docker.com/engine/reference/commandline/exec/

docker exec -it _container_ bash

should do the trick

The file is in /usr/local/lib/python3.9/site-packages/matrix_client, I think.

@surakin
Copy link

surakin commented Jul 22, 2021

matrix-org/matrix-python-sdk#321 has been merged, not sure who need to update the integration 🤔

@johansmitsnl
Copy link
Contributor

@surakin first we need a release of it

@johansmitsnl
Copy link
Contributor

I have opened up a PR with the version bump, see #53508
Now i needs approval to run the tests.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants