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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
XMPP HTTP upload #17426
XMPP HTTP upload #17426
Conversation
allow user to specify unverified SSL request to URL cleaner code catch more exceptions
It seems that all servers that I'm using do not support working with files/images. Service call run without error. {
"message": "{{ now() }}",
"title": "The sun is {% if is_state('sun.sun', 'above_horizon') %}up{% else %}down{% endif %}!",
"data": {
"url": "https://github.com/home-assistant/home-assistant.io/raw/next/source/images/favicon-192x192.png"
}
} According to the code the sending of the message and the file are two tasks. In my case the text message alone works but not if there is a file attached (as in the service call above). Shouldn't at least the message get through? |
Uff, after 10 min there is the error: 2018-10-15 23:26:37 INFO (MainThread) [homeassistant.components.notify.xmpp] getting file from https://github.com/home-assistant/home-assistant.io/raw/next/source/images/favicon-192x192.png
2018-10-15 23:37:32 ERROR (MainThread) [homeassistant.core] Error doing job: Task was destroyed but it is pending!
2018-10-15 23:37:32 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
slixmpp.exceptions.IqError: <iq xml:lang="en" to="notifications@jabber.me/home-assistant" from="dict.jabber.me" type="error" id="89220499-2768-4abd-b5dd-7f3aa7c74d49-23"><query xmlns="http://jabber.org/protocol/disco#info" /><error code="501" type="cancel"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">The feature requested is not implemented by the recipient or server and therefore cannot be processed.</text></error></iq> |
I'll have a look. Maybe I've to do extra service discovery earlier to see if the server supports it. Or maybe we can set a shorter timeout. I'm on it! |
Woooow...that's awesome dude! I was praying for soooo long to get this feature.please be aware that the pic has to be wrapped into oob to make it compatible with conversations and other XMPP clients We also need to know which server is used but normally if the component works according to the xep there shouldn't be any problem |
removed calls for roster and presence added timeout for upload request call cleared up debug, info, warning messages cleared up requests call for secure and insecure retrieval of image catching IqError, IqTimeout, XMPPError from slixmpp docstring updated
@fabaff I overlooked the
the XMPP lib checks on its own if the server supports XEP_0363, if not, an exception is caught and an error is logged. @thundergreen I know about OOB. The docs will document that the server needs to have XEP_0363 enabled: future-docs. Also I'm testing with Conversations. It would be great if you could test the code as well, with different clients when the beta is out; whenever this will be merged. |
@flowolf I'll test it as soon as it is out. Not clear how to attach the picture ....with data? Afaik will the lib itself take care of oob and the rest ..I just wouldn't know how to implement this. I'm really excited to test. Unfortunately I only use conversations...well more like a custom fork but in the core the same with all xmop standards included ..so testing would have same base. Example script.yaml entry5_send_jabber_message_with_image_and_text: |
@thundergreen the second |
@flowolf not sure if it speaks against Hass architecture to rename it into file.if not I'd recommend that . Are u also looking into possibility to upload into Muc as I c eater a special Muc to receive messages ... Instead of setting up Multiple notifier . Just out of curiosity..is it also possible to let the component look for latest file or having something like a regex or time range? I also was thinking about having a generated videofile of pics taken the whole day..but I guess that's another component Edit: found folder watchdog https://www.home-assistant.io/components/folder_watcher/ So let it to data..like this it is compliant to the other notification platforms |
I reproduced the problem. Currently when trying to send a file through I checked with @thundergreen 's ejabberd, and it worked. My prosody server works fine as well. The behavior with jabber.sk is that slixmpp does not handle the discovery correctly, does not see or react to the upload feature, and/or waits around for responses from servers. Not sure what goes on. I opened another bug report, because working around the problem by specifying a timeout for the upload is fruitless. |
guessing filetypes and mimetypes with stdlib mimetypes setting a random filename for privacy working around slixmpp timeout issues with asyncio.wait_for
Is it possible to push this pr toi test ? |
I cleaned up the code, and added support for sending file/images to rooms. the code is as feature complete as I can get it for HTTP-upload. @fabaff please have another look. |
Sounds great .thanks for that.hope it will be merged into Dev branch |
there is a fix of some issues on the way in slixmpp. I'll integrate those with a new version. |
added NotConnectedError, removed double catches of IqErrors removed asyncio import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some files could not be reviewed due to errors:
Traceback (most recent call last):
Traceback (most recent call last): File "/home/linters/.local/bin/flake8", line 7, in from flake8.main.cli import main ModuleNotFoundError: No module named 'flake8'
version 1.4.1 fixes the issues with jabber.sk. The server still is has issues of it's own (which are reported), but sending images will work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some files could not be reviewed due to errors:
Traceback (most recent call last):
Traceback (most recent call last): File "/home/linters/.local/bin/flake8", line 7, in from flake8.main.cli import main ModuleNotFoundError: No module named 'flake8'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I have added a few comments that you may want to address but nothing big.
fixed possible path issue for foo/../bar/ paths fixed possible access for non-whitelisted files fixed None or X fixed try-else block, moved else block into try fixed raising error in upload_file if url is None fixed using data.get after it's already been checked fixed added docstring for tiny get_url function
Description:
Add support for sending files through Jabber and HTTP upload (XEP_0363)
can load a file from a local file or a remote URL. e.g. images. 馃柤
Related issue (if applicable): none
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#6788
Example entry for
configuration.yaml
(if applicable):Checklist:
tox
. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.If the code does not interact with devices: