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

Apprise fails under Python 3.5 #456

Closed
clach04 opened this issue Oct 3, 2020 · 9 comments · Fixed by #462
Closed

Apprise fails under Python 3.5 #456

clach04 opened this issue Oct 3, 2020 · 9 comments · Fixed by #462

Comments

@clach04
Copy link
Contributor

clach04 commented Oct 3, 2020

I made a quick apprise-telegram listener and this works with Python2 but fails with Python 3.5.3 (default Raspbian).

 ERROR    [mqttwarn.services.apprise-telegram] Error sending message to n/a: There is no current event loop in thread 'Thread-2'.

on apobj.notify() call.

config extract:

[config:apprise-telegram]
module   = 'apprise'
baseuri  = 'tgram://TOKENS GO HERE'
; Surrogate for satisfying machinery.
targets  = {
    'n/a' : [''],
    }

[apprise-test]
topic    = apprise/#
targets  = apprise-telegram
format   = Alarm from {device}: {payload}
title    = Alarm from {device}

[apprise__telegram]
targets =  apprise-telegram

test:

echo '{"device": "foobar", "payload": "this is the payload"}' | mosquitto_pub -t 'apprise/foo' -l
echo 'this is the payload' | mosquitto_pub -t 'apprise__telegram' -l
@amotl
Copy link
Member

amotl commented Oct 11, 2020

Dear @clach04,

thanks for reporting this and for providing a complete configuration in order to be able to reproduce your observations.

When using Python 3.9.0b5, it seems to work flawlessly:

2020-10-11 21:52:56,436 DEBUG    [mqttwarn.services.apprise-telegram] Sending notification to Apprise n/a, addresses: ['']
2020-10-11 21:52:56,438 DEBUG    [apprise                  ] Loaded Telegram URL: tgram://270485614%3AAAHfiqksKZ8WmR2zSjiQ7_v4TMAKdiHm9T0//?image=False&detect=yes&format=text&overflow=upstream&rto=4.0&cto=4.0&verify=yes
2020-10-11 21:52:56,438 INFO     [apprise                  ] Notifying 1 service(s) asynchronously.
2020-10-11 21:52:56,439 DEBUG    [asyncio                  ] Using selector: KqueueSelector
2020-10-11 21:52:56,439 DEBUG    [apprise.URLBase          ] Telegram User Detection POST URL: https://api.telegram.org/bot270485614:AAHfiqksKZ8WmR2zSjiQ7_v4TMAKdiHm9T0/getUpdates (cert_verify=True)
2020-10-11 21:52:56,451 DEBUG    [urllib3.connectionpool   ] Starting new HTTPS connection (1): api.telegram.org:443
2020-10-11 21:52:56,537 DEBUG    [urllib3.connectionpool   ] https://api.telegram.org:443 "POST /bot270485614:AAHfiqksKZ8WmR2zSjiQ7_v4TMAKdiHm9T0/getUpdates HTTP/1.1" 401 58
2020-10-11 21:52:56,539 WARNING  [apprise.URLBase          ] Failed to detect the Telegram user: (401) Unauthorized.
2020-10-11 21:52:56,539 DEBUG    [apprise.URLBase          ] Response Details:
b'{"ok":false,"error_code":401,"description":"Unauthorized"}'
2020-10-11 21:52:56,539 WARNING  [apprise.URLBase          ] There were not Telegram chat_ids to notify.
2020-10-11 21:52:56,541 ERROR    [mqttwarn.services.apprise-telegram] Sending message using Apprise failed
2020-10-11 21:52:56,541 WARNING  [mqttwarn.core            ] Notification of apprise-telegram for `apprise/foo' FAILED or TIMED OUT

I am using the token from https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token, so the (401) Unauthorized was expectable.

With kind regards,
Andreas.

@amotl
Copy link
Member

amotl commented Oct 11, 2020

Indeed, when using Python 3.5, it reports the same thing you have been able to observe.

2020-10-11 21:58:42,759 ERROR    [mqttwarn.services.apprise-telegram] Error sending message to n/a: There is no current event loop in thread 'Thread-2'.
.../services/apprise.py:58: RuntimeWarning: coroutine 'AsyncNotifyBase.async_notify' was never awaited

@amotl
Copy link
Member

amotl commented Oct 11, 2020

By downgrading to Apprise 0.8.7 (#462), the error goes away.

cc @caronc

@amotl
Copy link
Member

amotl commented Oct 11, 2020

I just found caronc/apprise#273, which adds Python asyncio integration to Apprise 0.8.8 in order to send notifications asynchronously.

@caronc says:

You can set async_mode to False (it defaults to True) in the AppriseAsset() object if you want to go back to the legacy way of sending notifications.

#462 implements that.

@amotl amotl linked a pull request Oct 11, 2020 that will close this issue
@amotl amotl changed the title Apprise fails under Python3 Apprise fails under Python 3.5 Oct 11, 2020
@caronc
Copy link

caronc commented Oct 12, 2020

@amotl thanks for the mention. I'll look into this one and see what I can figure out.

Edit: I can't reproduce this issue; I've identified the steps I've taken to reproduce this in the issue (cross referenced below). Can you spot anything I'm doing differently?

@clach04
Copy link
Contributor Author

clach04 commented Oct 13, 2020

Thanks @amotl for the detailed reply and fix!.

Python 3.9 is really new and not available on all platforms yet, so good to know that's an option for the future :-) I'm deploying on a Raspberry Pi (and other SBCs) and 3.5 is the latest available without manually building Python.

I've not had a chance to pull down the latest code to see the new fix (not sure when I'll have time).

Your workaround was super easy and fast to apply:

pip uninstall apprise
pip install apprise==0.8.7

Worked a treat 👍

I'm excited about Apprise as it means I can code a single notification plugin and have it available to both mqttwarn and regular python code that's using Apprise - nice work!

@amotl
Copy link
Member

amotl commented Nov 22, 2020

Dear @clach04,

#462 made the Apprise integration go into non-async mode. It has been released through mqttwarn 0.20.0 on Oct 20, 2020. So, may I humbly ask you to review this issue in the context of installing mqttwarn[apprise]==0.20.0?

With kind regards,
Andreas.

@amotl amotl reopened this Nov 22, 2020
@amotl
Copy link
Member

amotl commented Jun 2, 2021

Hi again,

we do not longer run tests on Python 3.5. Thank you very much for your efforts on this back then!

@clach04: I also believe you are satisfied with the workaround you discovered? Feel free to reopen when appropriate.

With kind regards,
Andreas.

@amotl amotl closed this as completed Jun 2, 2021
@clach04
Copy link
Contributor Author

clach04 commented Jun 2, 2021

@amotl Apologies for not responding sooner, I either missed or forgot the request to test with headrev code :-(

Yes, I'm happy with original workaround. I do have a project that I'd like to start that would use this (not sure when I'll get time to start though....) where I'll make sure I use headrevs. If I hit any issues I'll be sure to open a ticket and cross reference to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants