home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.67k stars 30.42k forks source link

XMPP component not working after upgrading to 0.87 #20860

Closed thundergreen closed 4 years ago

thundergreen commented 5 years ago

Home Assistant release with the issue:

0.87 **Last working Home Assistant release (if known):** 0.86.4 **Operating environment (Hass.io/Docker/Windows/etc.):** venv install **Component/platform:** https://www.home-assistant.io/components/notify.xmpp/ **Description of problem:** notify XMPP not longer working after upgrading from 0.86.4 to 0.87--> See Traceback attached **Problem-relevant `configuration.yaml` entries and (fill out even if it seems unimportant):** ```yaml notify: - name: thorsten platform: xmpp host: 192.168.1.100 port: 5222 sender: home-assistant@emevth.no-ip.biz password: xxxxxxxxxxxxxxxxxxxxxx recipient: thorsten@emevth.no-ip.biz tls: true ``` **Traceback (if applicable):** ``` 2019-02-08 10:41:01 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback _SelectorSocketTransport._read_ready() Traceback (most recent call last): File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run self._callback(*self._args) File "/usr/lib/python3.6/asyncio/selector_events.py", line 732, in _read_ready self._protocol.data_received(data) File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/xmlstream.py", line 406, in data_received self._spawn_event(xml) File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/xmlstream.py", line 970, in _spawn_event stanza = self._build_stanza(xml) File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/xmlstream.py", line 951, in _build_stanza stanza = stanza_type(self, xml) File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 1389, in __init__ ElementBase.__init__(self, xml, parent) File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 415, in __init__ if self.setup(xml): File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/stanza/stream_features.py", line 27, in setup self.values = self.values File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 614, in _set_stanza_values self[full_interface] = value File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 752, in __setitem__ lang=lang) File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 958, in _set_sub_text return self._del_sub(name, lang=lang) File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 1039, in _del_sub parent = self.xml.find(parent_path) File "/usr/lib/python3.6/xml/etree/ElementTree.py", line 298, in find return ElementPath.find(self, path, namespaces) File "/usr/lib/python3.6/xml/etree/ElementPath.py", line 298, in find return next(iterfind(elem, path, namespaces), None) TypeError: 'NoneType' object is not an iterator ``` **Additional information:**
gpgmailencrypt commented 5 years ago

same here with raspbian strech

marconfus commented 5 years ago

My component (also based on slixmpp) fails with the same error since 0.87. It only happens in my "fully configured" HA instance. In the stripped down dev instance it still works fine. The error is not always there. After a couple of restarts it starts to work again.

thundergreen commented 5 years ago

@marconfus May I ask which component you use? Do you have a custom component?

marconfus commented 5 years ago

Yes, it's a custom climate device for Bosch thermostats which isn't in the official codebase yet. https://github.com/marconfus/ha-nefit-ng

It uses the same XMPP library and shows the same error. To validate this I also installed the XMPP notify component. Unfortunately I am not able to reproduce it in my dev environment and haven't found a good way to debug my prod env which is in a Hass.io installation.

Are you able to reproduce the error in a more or less empty/base venv installation of HA?

thundergreen commented 5 years ago

I dunno what they changed but it seems group chats don't work but direct messages do.. For example I got my xiaomi map sent but not all my notifications about lights etc... the only backtrace I have is the part I posted

marconfus commented 5 years ago

Hm, the functions in the stacktrace get the exact same parameters in case it works and when it fails. Also when it works, it works all the time and when it fails it fails all the time until you restart the python process... As the error only triggers when certain(?) other components are loaded, I guess it's some kind of internal error/racecondition in async Python or elsewhere. But I have absolutely no idea how to debug this...

thundergreen commented 5 years ago

I figured out that one to one works bit group chat fails

marconfus commented 5 years ago

So, I modified slixmpp to use lxml instead of xml. In stanzabase.py and xmlstream.py replace from xml.etree import cElementTree as ET with from lxml import etree as ET and added a try/catch block to stanzabase.py around the line from the stacktrace.

            try:
                parent = self.xml.find(parent_path)
            except:
                parent = None

This seems to works all the time.... (just adding the try/catch block without switching to lxml leads to other errors)

marconfus commented 5 years ago

I've opened a bug report at slixmpp: https://lab.louiz.org/poezio/slixmpp/issues/3429

thundergreen commented 5 years ago

I guess xmpp will be fixed in version 0.89 ?

thundergreen commented 5 years ago

do we have some news here ? I only get pictures sent to my xmpp client.

marconfus commented 5 years ago

I don't think there is anybod working on this. I guess it's because the bug only affects a couple of users. You could try to find the combination of active components that are necessary to trigger the bug. I.e. do you see the bug in an HA installation with only the xmpp component installed? And then add your other components until the bug triggers... I have a workaround for my component and not enough time to dig deeper. Sorry.

thundergreen commented 5 years ago

Could you share your workaround lease and i will add it :) would be nice ..

thanks mate

marconfus commented 5 years ago

I have forked slixmpp and used that instead: https://github.com/poezio/slixmpp/compare/master...marconfus:master https://github.com/marconfus/ha-nefit-ng/commit/89310658ff192f242fd3c508f423286ca36000d2

thundergreen commented 5 years ago

@marconfus works like a charm. I also forked your repo now :)

meisterlampe commented 5 years ago

I get a similar error. It could be related, but I'm not sure. I'll try @marconfus workaround in the next days. For me it occurs all the time, so it could also be a configuration problem on my side. Anyway the trace looks related.

Just started testing HA two weeks ago, so my installation is not that complex to mind. Maybe it helps, when I list it here:

My configuration contains:

notify:
  - name: jabber
    platform: xmpp
    sender: hass@myserver.com
    password: SECRET
    recipient: me@myserver.com

The error I get is:

2019-02-23 21:42:36 ERROR (MainThread) [homeassistant.core] Error doing job: Fatal error on transport TCPTransport
Traceback (most recent call last):
  File "uvloop/handles/stream.pyx", line 827, in uvloop.loop.__uv_stream_on_read_impl
  File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/xmlstream.py", line 406, in data_received
self._spawn_event(xml)
  File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/xmlstream.py", line 970, in _spawn_event
stanza = self._build_stanza(xml)
  File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/xmlstream.py", line 951, in _build_stanza
stanza = stanza_type(self, xml)
  File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/stanzabase.py", line 1390, in __init__
ElementBase.__init__(self, xml, parent)
  File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/stanzabase.py", line 416, in __init__
if self.setup(xml):
  File "/usr/local/lib/python3.7/site-packages/slixmpp/stanza/stream_features.py", line 27, in setup
self.values = self.values
  File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/stanzabase.py", line 615, in _set_stanza_values
self[full_interface] = value
  File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/stanzabase.py", line 753, in __setitem__
lang=lang)
  File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/stanzabase.py", line 959, in _set_sub_text
return self._del_sub(name, lang=lang)
  File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/stanzabase.py", line 1040, in _del_sub
parent = self.xml.find(parent_path)
  File "/usr/local/lib/python3.7/xml/etree/ElementTree.py", line 299, in find
return ElementPath.find(self, path, namespaces)
  File "/usr/local/lib/python3.7/xml/etree/ElementPath.py", line 307, in find
return next(iterfind(elem, path, namespaces), None)
TypeError: 'NoneType' object is not an iterator
meisterlampe commented 5 years ago

Just tried the workaround and HA is finally sending messages. Thanks a lot 👍

meisterlampe commented 5 years ago

To test the workaround, I modified the source files in the homeassistant docker instance of my hassio install. Which works like a charm. But: That changes are lost, if I restart HA. When using normal docker images, I would use a custom dockerfile and make my modifications there. But the image is managed by the hassio supervisor which I don't know a lot about.

Do you have any ideas how to make changes like applying this workaround persistent on a hassio install?

marconfus commented 5 years ago

You could copy the original component and install it as a custom_component. The documentation says, that that is supported: https://developers.home-assistant.io/docs/en/creating_component_loading.html

Of course that is a terrible hack and it would be better to find the real cause of the problem...

meisterlampe commented 5 years ago

Thanks for the fast answer. I will try this. I hope the real cause can be found soon :-)

ehendrix23 commented 5 years ago

Adding my name to this issue. Testing use of slixmpp for Harmony component and getting same error.

thundergreen commented 5 years ago

I get new issue when trying to send a local file:

Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/usr/lib/python3.6/asyncio/selector_events.py", line 976, in _read_ready
    self._protocol.data_received(data)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/xmlstream.py", line 407, in data_received
    self._spawn_event(xml)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/xmlstream.py", line 971, in _spawn_event
    stanza = self._build_stanza(xml)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/xmlstream.py", line 952, in _build_stanza
    stanza = stanza_type(self, xml)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/stanza/iq.py", line 70, in __init__
    StanzaBase.__init__(self, *args, **kwargs)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 1394, in __init__
    ElementBase.__init__(self, xml, parent)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 427, in __init__
    reuse=False)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 508, in init_plugin
    plugin = plugin_class(parent=self, xml=existing_xml)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 427, in __init__
    reuse=False)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 508, in init_plugin
    plugin = plugin_class(parent=self, xml=existing_xml)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/plugins/xep_0004/stanza/form.py", line 35, in __init__
    ElementBase.__init__(self, *args, **kwargs)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 427, in __init__
    reuse=False)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 520, in init_plugin
    self.init_plugin(plugin_class.plugin_multi_attrib)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 508, in init_plugin
    plugin = plugin_class(parent=self, xml=existing_xml)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 417, in __init__
    if self.setup(xml):
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 112, in setup
    self.xml = ET.Element('')
  File "src/lxml/etree.pyx", line 2998, in lxml.etree.Element
  File "src/lxml/apihelpers.pxi", line 95, in lxml.etree._makeElement
  File "src/lxml/apihelpers.pxi", line 1549, in lxml.etree._getNsTag
  File "src/lxml/apihelpers.pxi", line 1584, in lxml.etree.__getNsTag
ValueError: Empty tag name

my script:

  3_send_jabber_message_with_local_image_path:
    alias: "Send Image via Jabber from local file"
    sequence:
      - service: notify.thorsten
        data:
          title: ""
          message: ""
          data:
            path: "/home/hass/.homeassistant/cam_snap_shots/front-door/record.mp4"

I am using this custom slix:

https://github.com/marconfus/slixmpp/archive/master.zip#slixmpp==1.4.2.1

Human commented 5 years ago

Any chance of reverting the slixmpp version used by hass to the one used in 0.86.4?

thundergreen commented 5 years ago

@Human Would be the best I think. But you can temporairly use the "dirty" workaround described above. It works but like mentioned: httpupload won't work

thundergreen commented 5 years ago

I asked in slixmpp channel for this issue and apparently we use wrong XML library

marconfus commented 5 years ago

Yes, in my "dirty fix" I changed the XML parser to lxml. Apparently this leeds to other errors in your scenario.

ehendrix23 commented 5 years ago

I just updated to Python 3.7.3 and issue is still present. :-( Was hoping maybe a fix through there. .

If I use my library (aioharmony) outside of Home Assistant I have no issues. If I use it within HA then I get the error.

ehendrix23 commented 5 years ago

Any chance of reverting the slixmpp version used by hass to the one used in 0.86.4?

slixmpp in 0.86.4 was 1.4.1. For my component (aioharmony) that I'm trying to get to work with XMPP I have tried both 1.4.1 and 1.4.2 in HA; both fail. No issues outside of HA.

thundergreen commented 5 years ago

I am sure it is not just slixmpp version related but something global in hass. I'd like seeing a dev for this component giving a feedback here.. unfortunately the xmpp platform is underestimated and not used that often like other platforms. But I think it should be maintained like every platform

ehendrix23 commented 5 years ago

Been adding a bunch of debug info to my local copy of slixmpp but so far haven't found anything. From what I can tell it is all going and working the same. But, I'm far from an expert when it comes to XMPP and the XML objects.

I've also been going through the release notes from 0.87 (as 0.86.4 was working and 0.87 not based on 1st posts here) but haven't been able to find anything or anything standing out that could be the explanation for it breaking.

Human commented 5 years ago

@ehendrix23 Are you able to do a git bisect to narrow down the commit that introduced the bug?

ehendrix23 commented 5 years ago

I could .... if I knew how. :-)

Human commented 5 years ago

@ehendrix23 Does this help? https://git-scm.com/docs/git-bisect

If I'm reading the tags right, you'd want to start the bisect at the commit for tag for 0.87 ( c366fa00d8f63c4ebe8398280ed342bd4903f7c0 ) and mark it as bad then mark the commit for tag 0.86.4 ( aa29eeba04a68234a46c298fabef88d3635922f5 ) as good. Then the bisect process will cut the commits between the two in half, letting you test each one and mark the result as good or bad. After a few iterations, it'll tell you which commit specifically introduced the bug.

Spectator-s commented 5 years ago

Just to confirm that i have the same issue (object is not an iterator), that i do prefer XMPP over other notification services, and I'm waiting for it to be resolved :). I am no programmer unfortunately so may not be of any help other than providing my logs if required.

Glotzon commented 5 years ago

Same issue here, not sure how the workaround works, but xmpp is the only way to send proper notifications. Please fix.

thundergreen commented 5 years ago

Strangely after upgrading today to --pre homeassistant 0.94.0 XMPP works like a charm... maybe a try it's worth @Glotzon

horstk commented 5 years ago

Can't confirm that homeassistant 0.94 works. The problem remains for me. I still have to use a custom component with the slixmpp package of @marconfus

mrwsl commented 5 years ago

Can't confirm either (Whenever I use xmpp notify I also use httpupload):

Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
    self._callback(*self._args)
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 730, in _read_ready
    self._protocol.data_received(data)
  File "/srv/homeassistant/lib/python3.5/site-packages/slixmpp/xmlstream/xmlstream.py", line 406, in data_received
    self._spawn_event(xml)
  File "/srv/homeassistant/lib/python3.5/site-packages/slixmpp/xmlstream/xmlstream.py", line 970, in _spawn_event
    stanza = self._build_stanza(xml)
  File "/srv/homeassistant/lib/python3.5/site-packages/slixmpp/xmlstream/xmlstream.py", line 951, in _build_stanza
    stanza = stanza_type(self, xml)
  File "/srv/homeassistant/lib/python3.5/site-packages/slixmpp/xmlstream/stanzabase.py", line 1390, in __init__
    ElementBase.__init__(self, xml, parent)
  File "/srv/homeassistant/lib/python3.5/site-packages/slixmpp/xmlstream/stanzabase.py", line 416, in __init__
    if self.setup(xml):
  File "/srv/homeassistant/lib/python3.5/site-packages/slixmpp/stanza/stream_features.py", line 27, in setup
    self.values = self.values
  File "/srv/homeassistant/lib/python3.5/site-packages/slixmpp/xmlstream/stanzabase.py", line 615, in _set_stanza_values
    self[full_interface] = value
  File "/srv/homeassistant/lib/python3.5/site-packages/slixmpp/xmlstream/stanzabase.py", line 753, in __setitem__
    lang=lang)
  File "/srv/homeassistant/lib/python3.5/site-packages/slixmpp/xmlstream/stanzabase.py", line 959, in _set_sub_text
    return self._del_sub(name, lang=lang)
  File "/srv/homeassistant/lib/python3.5/site-packages/slixmpp/xmlstream/stanzabase.py", line 1040, in _del_sub
    parent = self.xml.find(parent_path)
  File "/usr/lib/python3.5/xml/etree/ElementTree.py", line 297, in find
    return ElementPath.find(self, path, namespaces)
  File "/usr/lib/python3.5/xml/etree/ElementPath.py", line 298, in find
    return next(iterfind(elem, path, namespaces), None)
TypeError: 'NoneType' object is not an iterator
thundergreen commented 5 years ago

Thats' weird and strange.. I had similar problem with this XMPP and after just upgrading to 0.94 it was fixed. I know nothing was changed in XMPP component.. I am confused :P

nmartinho commented 5 years ago

Problem continues on 0.94.0

TypeError: 'NoneType' object is not an iterator

Spectator-s commented 5 years ago

Also confirm that not resolved in 0.94. NoneType' object is not an iterator

tomlevels commented 5 years ago

I also get the same error after updating to 0.94.

sesceu commented 5 years ago

Same here on 0.94.3.

nicuh commented 5 years ago

Same stack-trace for me in 0.94.3

Human commented 5 years ago

Still the same bug in 0.94.4

Human commented 5 years ago

In 0.95.4, the line numbers have changed, but it's still the same error:

Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/usr/lib/python3.6/asyncio/selector_events.py", line 721, in _read_ready
    self._protocol.data_received(data)
  File "/home/igo/.homeassistant/deps/lib/python3.6/site-packages/slixmpp/xmlstream/xmlstream.py", line 406, in data_received
    self._spawn_event(xml)
  File "/home/igo/.homeassistant/deps/lib/python3.6/site-packages/slixmpp/xmlstream/xmlstream.py", line 970, in _spawn_event
    stanza = self._build_stanza(xml)
  File "/home/igo/.homeassistant/deps/lib/python3.6/site-packages/slixmpp/xmlstream/xmlstream.py", line 951, in _build_stanza
    stanza = stanza_type(self, xml)
  File "/home/igo/.homeassistant/deps/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 1390, in __init__
    ElementBase.__init__(self, xml, parent)
  File "/home/igo/.homeassistant/deps/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 416, in __init__
    if self.setup(xml):
  File "/home/igo/.homeassistant/deps/lib/python3.6/site-packages/slixmpp/stanza/stream_features.py", line 27, in setup
    self.values = self.values
  File "/home/igo/.homeassistant/deps/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 615, in _set_stanza_values
    self[full_interface] = value
  File "/home/igo/.homeassistant/deps/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 753, in __setitem__
    lang=lang)
  File "/home/igo/.homeassistant/deps/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 959, in _set_sub_text
    return self._del_sub(name, lang=lang)
  File "/home/igo/.homeassistant/deps/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 1040, in _del_sub
    parent = self.xml.find(parent_path)
  File "/usr/lib/python3.6/xml/etree/ElementTree.py", line 298, in find
    return ElementPath.find(self, path, namespaces)
  File "/usr/lib/python3.6/xml/etree/ElementPath.py", line 298, in find
    return next(iterfind(elem, path, namespaces), None)
TypeError: 'NoneType' object is not an iterator
Human commented 5 years ago

@fabaff Hi! I and others have implemented these small changes described here to get XMPP working again in HASS. As the XMPP maintainer, if this were turned into a PR, would you accept the change?

jpljonkman commented 5 years ago

I'm using Hassos. Where can I find the stanzabase.py and xmlstream.py files?

marconfus commented 5 years ago

@fabaff Hi! I and others have implemented these small changes described here to get XMPP working again in HASS. As the XMPP maintainer, if this were turned into a PR, would you accept the change?

The dirty hack of mine you referenced is not in the homeassistant code, so it cannot be fixed here. It's the most obscure python problem I have ever seen and unfortunately nobody has an idea how to fix it. As long as I know, nobody is even able to reproduce it 100% (i.e. create a demo ha config that triggers the bug). If, at all, a workaround could be added to the slixmpp library -> https://github.com/poezio/slixmpp/pull/17 But this seems to lead to other errors.

Human commented 5 years ago

@marconfus Well, it could be fixed by forking slixmpp and making HASS use the fork instead of the mainline version.

Before I applied your workaround, I had 100% XMPP failure. If I get some time, I could derive a minimal example HASS configuration that causes the bug.