caronc / nzb-notify

Push Notifications to a large number of supported services for NZBGet and SABnzbd (based on Apprise)
GNU General Public License v3.0
129 stars 15 forks source link

UnboundLocalError: local variable 'context' referenced before assignment #36

Closed vledder closed 6 years ago

vledder commented 6 years ago

Hi, when postprocessing a download notify is triggered to notify me when a download is finished, though it fails (see logging). The script is working fine on notifying me onQueue event. so dont know what's happening. Maybe you can have a look?

Post-process-script nzbToMedia/Notify.py for Greys.Anatomy.S14E09.720p.HDTV.x264-AVS failed Notify: [DEBUG] Exiting with return code: 94 Notify: UnboundLocalError: local variable 'context' referenced before assignment Notify: context=context, Notify: File "/share/MD0_DATA/.qpkg/NZBGet/nzbget/scripts/nzbToMedia/Notify/nzbget/ScriptBase.py", line 2487, in api_connect Notify: if not self.api_connect(): Notify: File "/share/MD0_DATA/.qpkg/NZBGet/nzbget/scripts/nzbToMedia/Notify/nzbget/PostProcessScript.py", line 595, in get_statistics Notify: stats = self.get_statistics() Notify: File "/share/MD0_DATA/.qpkg/NZBGet/nzbget/scripts/nzbToMedia/Notify.py", line 1162, in postprocess_main Notify: exit_code = main_function(*args, **kwargs) Notify: File "/share/MD0_DATA/.qpkg/NZBGet/nzbget/scripts/nzbToMedia/Notify/nzbget/ScriptBase.py", line 3035, in run Notify: Traceback (most recent call last): Notify: [DEBUG] get(system) CONTROLPASSWORD="tegbzn6789" Notify: [DEBUG] get(system) CONTROLUSERNAME="nzbget" Notify: [DEBUG] get(system) CONTROLPORT="6789" Notify: [DEBUG] get(system) SECUREKEY="" Notify: [DEBUG] get(system) SECURECERT="" Notify: [DEBUG] get(system) SECURECONTROL="no" Notify: [DEBUG] get(config) INCLUDELOGS="OnFailure" Notify: [DEBUG] get(config) INCLUDEFILES="yes" Notify: [DEBUG] get(config) INCLUDESTATS="yes" Notify: [DEBUG] get(config) ONSUCCESS="yes" Notify: [DEBUG] get(config) ONFAILURE="yes" Notify: [DEBUG] get(config) SERVERS="tgram://" Notify: [DEBUG] get(config) INCLUDEIMAGE="yes" Notify: [DEBUG] get(default) BODY=None Notify: [DEBUG] get(default) TITLE=None Notify: [DEBUG] Opened connection to SQLite Database: /share/Download/nzbget/tmp/nzbget/nzbget.db Notify: [DEBUG] get(config) SERVERS="tgram://" Notify: [DEBUG] get(system) NZBID="1398" Notify: NZBParse - NZB-File parsed 2 meta entries Notify: NZB-File detected: Greys.Anatomy.S14E09.720p.HDTV.x264-AVS.nzb.queued Notify: [DEBUG] NZB-Files located: Greys.Anatomy.S14E09.720p.HDTV.x264-AVS.nzb.queued (2018-01-19 05:41:50) Notify: [DEBUG] Allowed Greys.Anatomy.S14E09.720p.HDTV.x264-AVS.nzb.queued (regex) Notify: [DEBUG] get_files('/share/Download/nzbget/nzb') with 1 filter(s) Notify: [DEBUG] get(system) NZBDIR="/share/Download/nzbget/nzb" Notify: [DEBUG] get_files('/share/MD0_DATA/Download/nzbget/tmp') with 1 filter(s) Notify: [DEBUG] Script Mode: postprocess Executing post-process-script nzbToMedia/Notify.py for Greys.Anatomy.S14E09.720p.HDTV.x264-AVS

caronc commented 6 years ago

Out of curiosity, what version of Python are you using?

vledder commented 6 years ago

copy from terminal:

[~] # which python
/opt/bin/python
[~] # python --version
Python 2.7.13

hope it helps

caronc commented 6 years ago

Hmm.. have another shot; i pushed a small change yesterday that may be the issue. You'll need to check out the latest master branch again.

vledder commented 6 years ago

well the unboundLocalError seems to be gone, though in the end it still fails (The script is still working fine on notifying me onQueue event):

Post-process-script nzbToMedia/Notify.py for Lucifer_S03E13_720p_HEVC_x265-MEGUSTA failed
Notify: [DEBUG] Exiting with return code: 94
Notify: TypeError: __init__() got an unexpected keyword argument 'context'
Notify: context=None,
Notify: File "/share/MD0_DATA/.qpkg/NZBGet/nzbget/scripts/nzbToMedia/Notify/nzbget/ScriptBase.py", line 2487, in api_connect
Notify: if not self.api_connect():
Notify: File "/share/MD0_DATA/.qpkg/NZBGet/nzbget/scripts/nzbToMedia/Notify/nzbget/PostProcessScript.py", line 595, in get_statistics
Notify: stats = self.get_statistics()
Notify: File "/share/MD0_DATA/.qpkg/NZBGet/nzbget/scripts/nzbToMedia/Notify.py", line 1162, in postprocess_main
Notify: exit_code = main_function(*args, **kwargs)
Notify: File "/share/MD0_DATA/.qpkg/NZBGet/nzbget/scripts/nzbToMedia/Notify/nzbget/ScriptBase.py", line 3038, in run
Notify: Traceback (most recent call last):
Notify: [DEBUG] get(system) CONTROLPASSWORD="tegbzn6789"
Notify: [DEBUG] get(system) CONTROLUSERNAME="nzbget"
Notify: [DEBUG] get(system) CONTROLPORT="6789"
Notify: [DEBUG] get(system) SECUREKEY=""
Notify: [DEBUG] get(system) SECURECERT=""
Notify: [DEBUG] get(system) SECURECONTROL="no"
Notify: [DEBUG] get(config) INCLUDELOGS="OnFailure"
Notify: [DEBUG] get(config) INCLUDEFILES="yes"
Notify: [DEBUG] get(config) INCLUDESTATS="yes"
Notify: [DEBUG] get(config) ONSUCCESS="yes"
Notify: [DEBUG] get(config) ONFAILURE="yes"
Notify: [DEBUG] get(config) SERVERS="tgram://<id>"
Notify: [DEBUG] get(config) INCLUDEIMAGE="yes"
Notify: [DEBUG] get(default) BODY=None
Notify: [DEBUG] get(default) TITLE=None
Notify: [DEBUG] Opened connection to SQLite Database: /share/Download/nzbget/tmp/nzbget/nzbget.db
Notify: [DEBUG] get(config) SERVERS="tgram://<id>"
Notify: [DEBUG] get(system) NZBID="1407"
Notify: NZBParse - NZB-File parsed 0 meta entries
Notify: NZB-File detected: Lucifer_S03E13_720p_HEVC_x265-MEGUSTA.nzb.queued
Notify: [DEBUG] NZB-Files located: Lucifer_S03E13_720p_HEVC_x265-MEGUSTA.nzb.queued (2018-01-30 19:23:24)
Notify: [DEBUG] Allowed Lucifer_S03E13_720p_HEVC_x265-MEGUSTA.nzb.queued (regex)
Notify: [DEBUG] get_files('/share/Download/nzbget/nzb') with 1 filter(s)
Notify: [DEBUG] get(system) NZBDIR="/share/Download/nzbget/nzb"
Notify: [DEBUG] get_files('/share/MD0_DATA/Download/nzbget/tmp') with 1 filter(s)
Notify: [DEBUG] Script Mode: postprocess
Executing post-process-script nzbToMedia/Notify.py for Lucifer_S03E13_720p_HEVC_x265-MEGUSTA
caronc commented 6 years ago

I'll just fill you in on what is happening here: During PostProcessing (only), if the INCLUDESTATS is set (which it is for you), the script connects back to NZBGet and fetches all of these juicy statistics (transfer speeds, etc) so it can include them in your notification. Not all notifications support all of this extra detail (but some do). I'm not sure why your end is throwing the exception that it is; especially on a function that should be present (supporting the context argument you're getting an error on).

I pushed one more commit that will NOT fix the problem, but it will hopefully give us more insight on what it is that is causing us this grief. If you could just pull the master down one more time and giver another go (failure). Just keep me posted on your results so we can figure this one out! :smile:

p.s. Thank you for all your time and patience on this btw!

vledder commented 6 years ago

Alright, gave it another try with the same NZB as yesterday with the new extra debugging code.. Guess what: it now processed successful. Dunno why.. any clues? I'll test with some more nzb's

Post-process-script nzbToMedia/Notify.py for Lucifer_S03E13_720p_HEVC_x265-MEGUSTA successful
Notify: [DEBUG] Exiting with return code: 93
Notify: [DEBUG] Telegram Payload: {'text': u'<b>Download Successful</b>\r\n## Lucifer_S03E13_720p_HEVC_x265-MEGUSTA ##\r\nStatus: SUCCESS/HEALTH\r\n\r\n### File(s) ###\r\n * Lucifer.S03E13.720p.HEVC.x265-MeGusta.mkv (311.45 MB)\r\n * Torrent.Downloaded.From.WWW.TORRENTING.COM.txt (84.00 B)\r\n * newz[NZB].nfo (13.00 B)', 'parse_mode': 'HTML', 'chat_id': '--'}
Notify: [DEBUG] Telegram POST URL: https://api.telegram.org/b---/sendMessage (cert_verify=False)
Notify: [DEBUG] Telegram POST URL: https://api.telegram.org/b---/sendMessage
Notify: [DEBUG] Server parsed to: {'host': '--', 'user': None, 'query': '--', 'url': 'tgram://---', 'path': '/--/', 'fullpath': '/---/--', 'password': None, 'port': None, 'qsd': {}, 'schema': 'tgram'}
Notify: [DEBUG] get(config) INCLUDEIMAGE="yes"
Notify: [DEBUG] get_files('/share/Download/nzbget/dst/Lucifer_S03E13_720p_HEVC_x265-MEGUSTA') with 0 filter(s)
Notify: [DEBUG] Failure Reason: __init__() got an unexpected keyword argument 'context'
Notify: [DEBUG] API connection failed @ http://nzbget:tegbzn6789@127.0.0.1:6789/xmlrpc
Notify: [DEBUG] get(system) CONTROLPASSWORD="tegbzn6789"
Notify: [DEBUG] get(system) CONTROLUSERNAME="nzbget"
Notify: [DEBUG] get(system) CONTROLPORT="6789"
Notify: [DEBUG] get(system) SECUREKEY=""
Notify: [DEBUG] get(system) SECURECERT=""
Notify: [DEBUG] get(system) SECURECONTROL="no"
Notify: [DEBUG] get(config) INCLUDELOGS="OnFailure"
Notify: [DEBUG] get(config) INCLUDEFILES="yes"
Notify: [DEBUG] get(config) INCLUDESTATS="yes"
Notify: [DEBUG] get(config) ONSUCCESS="yes"
Notify: [DEBUG] get(config) ONFAILURE="yes"
Notify: [DEBUG] get(config) SERVERS="tgram://<id>"
Notify: [DEBUG] get(config) INCLUDEIMAGE="yes"
Notify: [DEBUG] get(default) BODY=None
Notify: [DEBUG] get(default) TITLE=None
Notify: [DEBUG] Opened connection to SQLite Database: /share/Download/nzbget/tmp/nzbget/nzbget.db
Notify: [DEBUG] get(config) SERVERS="tgram://<id>"
Notify: [DEBUG] get(system) NZBID="1408"
Notify: NZBParse - NZB-File parsed 0 meta entries
Notify: NZB-File detected: Lucifer_S03E13_720p_HEVC_x265-MEGUSTA.nzb.2.queued
Notify: [DEBUG] NZB-Files located: Lucifer_S03E13_720p_HEVC_x265-MEGUSTA.nzb.queued (2018-01-30 19:29:58)
Notify: [DEBUG] NZB-Files located: Lucifer_S03E13_720p_HEVC_x265-MEGUSTA.nzb.2.queued (2018-01-31 10:13:44)
Notify: [DEBUG] Allowed Lucifer_S03E13_720p_HEVC_x265-MEGUSTA.nzb.2.queued (regex)
Notify: [DEBUG] Allowed Lucifer_S03E13_720p_HEVC_x265-MEGUSTA.nzb.queued (regex)
Notify: [DEBUG] get_files('/share/Download/nzbget/nzb') with 1 filter(s)
Notify: [DEBUG] get(system) NZBDIR="/share/Download/nzbget/nzb"
Notify: [DEBUG] get_files('/share/MD0_DATA/Download/nzbget/tmp') with 1 filter(s)
Notify: [DEBUG] Script Mode: postprocess
Executing post-process-script nzbToMedia/Notify.py for Lucifer_S03E13_720p_HEVC_x265-MEGUSTA
caronc commented 6 years ago

Guess what: it now processed successful. Dunno why.. any clues?

Yeah... Here:

Notify: [DEBUG] Failure Reason: init() got an unexpected keyword argument 'context' Notify: [DEBUG] API connection failed @ http://nzbget:tegbzn6789@127.0.0.1:6789/xmlrpc

Same error, it's just masked behind a exception handler I added. It's not a fix though. It's just allowing you to pass that part you were getting stuck on before. Unfortunately you still won't be getting the statistics in your Telegram notice.

Just for my own info: What Linux flavor and version are you using to host your copy of NZBGet? The problem seems to be related to your Python build... v2.7.13 is a great version, but your copy of it seems wonky for some reason. I'll do some more research and get back to you here though. I can't say this for sure, but something seems off.

vledder commented 6 years ago

Ah alright. That's correct; I'm not seeing any statistics indeed. I'm running NZBGet 19.1 on a QNAP TS-212 with version 4.3.3.0404. So yeah I'm using their default linux distribution. Also I installed python there from the appCenter (QKPG). All other programs/functions which need Python behave normally without errors.

If there's anything I can do lemme know.

caronc commented 6 years ago

Lets try this again; have another checkout of the master and keep me posted.

vledder commented 6 years ago

alright! I see you added some additional debug info, though no difference in outcome. Hope the additional debug info gives you some ideas.

Post-process-script nzbToMedia/Notify.py for Lucifer_S03E13_720p_HEVC_x265-MEGUSTA successful
Notify: [DEBUG] Exiting with return code: 93
Notify: [DEBUG] Telegram Payload: {'text': u'<b>Download Successful</b>\r\n## Lucifer_S03E13_720p_HEVC_x265-MEGUSTA ##\r\nStatus: SUCCESS/HEALTH\r\n\r\n### File(s) ###\r\n * Lucifer.S03E13.720p.HEVC.x265-MeGusta.mkv (311.45 MB)\r\n * Torrent.Downloaded.From.WWW.TORRENTING.COM.txt (84.00 B)\r\n * newz[NZB].nfo (13.00 B)', 'parse_mode': 'HTML', 'chat_id': '--'}
Notify: [DEBUG] Telegram POST URL: https://api.telegram.org/bot<id>:<id>/sendMessage (cert_verify=False)
Notify: [DEBUG] Telegram POST URL: https://api.telegram.org/bot<id>:<id>/sendMessage
Notify: [DEBUG] Server parsed to: {'host': '<id>', 'user': None, 'query': '<id>', 'url': 'tgram://<id>/<id>/<id>', 'path': '/<id>/', 'fullpath': '/<id>/<id>', 'password': None, 'port': None, 'qsd': {}, 'schema': 'tgram'}
Notify: [DEBUG] get(config) INCLUDEIMAGE="yes"
Notify: [DEBUG] get_files('/share/Download/nzbget/dst/Lucifer_S03E13_720p_HEVC_x265-MEGUSTA') with 0 filter(s)
Notify: [DEBUG] Failure Reason: __init__() got an unexpected keyword argument 'context'
Notify: [DEBUG] API connection failed @ http://nzbget:tegbzn6789@127.0.0.1:6789/xmlrpc
Notify: [DEBUG] get(system) CONTROLPASSWORD="tegbzn6789"
Notify: [DEBUG] get(system) CONTROLUSERNAME="nzbget"
Notify: [DEBUG] get(system) CONTROLPORT="6789"
Notify: [DEBUG] get(system) SECUREKEY=""
Notify: [DEBUG] get(system) SECURECERT=""
Notify: [DEBUG] get(system) SECURECONTROL="no"
Notify: [DEBUG] get(config) INCLUDELOGS="OnFailure"
Notify: [DEBUG] get(config) INCLUDEFILES="yes"
Notify: [DEBUG] get(config) INCLUDESTATS="yes"
Notify: [DEBUG] get(config) ONSUCCESS="yes"
Notify: [DEBUG] get(config) ONFAILURE="yes"
Notify: [DEBUG] get(config) SERVERS="tgram://<id>:<id>/<id>"
Notify: [DEBUG] get(config) INCLUDEIMAGE="yes"
Notify: [DEBUG] get(default) BODY=None
Notify: [DEBUG] get(default) TITLE=None
Notify: [DEBUG] Opened connection to SQLite Database: /share/Download/nzbget/tmp/nzbget/nzbget.db
Notify: [DEBUG] get(config) SERVERS="tgram://<id>:<id>/<id>"
Notify: [DEBUG] get(system) NZBID="1413"
Notify: NZBParse - NZB-File parsed 0 meta entries
Notify: NZB-File detected: Lucifer_S03E13_720p_HEVC_x265-MEGUSTA.nzb.queued
Notify: [DEBUG] NZB-Files located: Lucifer_S03E13_720p_HEVC_x265-MEGUSTA.nzb.queued (2018-02-05 20:30:14)
Notify: [DEBUG] Allowed Lucifer_S03E13_720p_HEVC_x265-MEGUSTA.nzb.queued (regex)
Notify: [DEBUG] get_files('/share/Download/nzbget/nzb') with 1 filter(s)
Notify: [DEBUG] get(system) NZBDIR="/share/Download/nzbget/nzb"
Notify: [DEBUG] get_files('/share/MD0_DATA/Download/nzbget/tmp') with 1 filter(s)
Notify: [DEBUG] OS: Linux 3.4.6
Notify: [DEBUG] Python v2.7.0
Notify: [DEBUG] Script Mode: postprocess
Executing post-process-script nzbToMedia/Notify.py for Lucifer_S03E13_720p_HEVC_x265-MEGUSTA
caronc commented 6 years ago

Sorry to take so long to get back to you! Now back on topic; one thing that stands out to me is what gets caught in the output of the script

Python v2.7.0

I realize you also stated this:

[\~] # which python /opt/bin/python [\~] # python --version Python 2.7.13

But it would appear you might have 2 versions of python installed because the scripts are definitely referencing a different version (v2.7.0)... well at least NZBGet is when it calls them... it's certainly not referencing the one you found in your /opt/bin/ directory.

Is there any way you can check for an update with your QNAP server? You want to update to at the very least 2.7.5 (where most of the major issues - especially the security related ones) have been implemented? This includes the section of code that is breaking on you right now.

Regardless, i pushed a small update to attempt to handle issue (3 times a charm... ?) if you can't do the update. You'll need to check out the master again (you know the drill).

Good luck! :smile:

vledder commented 6 years ago

Did the replace, but now I'm stuck at cert_verify=True. Can I set it to False somewhere (which file + line?) cause now it doesn't work at all anymore. Prolly a reference path which is not ok on my system also. Dunno. I'm not an Linux expert but I see where you're getting at with the different python versions. Not sure how to change the refer path to the python version found in opt. I'll have to dig.

for what its worth the log. Hope you have a quick answer on the cert_verify so I at least get some notifications :)

Notify: [DEBUG] Exiting with return code: 93
Notify: [DEBUG] Socket Exception: [Errno 1] _ssl.c:499: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm
Notify: A Connection error occured sending Telegram:id notification.
Notify: InsecurePlatformWarning
Notify: /share/MD0_DATA/.qpkg/NZBGet/nzbget/scripts/nzbToMedia/Notify/urllib3/util/ssl_.py:100: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
Notify: [DEBUG] Telegram (image) Payload: {'disable_notification': True, 'chat_id': 'id'}
Notify: [DEBUG] Telegram (image) POST URL: https://api.telegram.org/bot:id/sendPhoto (cert_verify=True)
Notify: [DEBUG] get(config) INCLUDEIMAGE="no"
Notify: [DEBUG] get_files('/share/Download/nzbget/dst/BBC - Trust me I_m a Doctor') with 0 filter(s)
Notify: [DEBUG] Failure Reason: __init__() got an unexpected keyword argument 'context'
Notify: [DEBUG] API connection failed @ http://nzbget:tegbzn6789@127.0.0.1:6789/xmlrpc
Notify: [DEBUG] get(system) CONTROLPASSWORD="tegbzn6789"
Notify: [DEBUG] get(system) CONTROLUSERNAME="nzbget"
Notify: [DEBUG] get(system) CONTROLPORT="6789"
Notify: [DEBUG] get(system) SECUREKEY=""
Notify: [DEBUG] get(system) SECURECERT=""
Notify: [DEBUG] get(system) SECURECONTROL="no"
Notify: [DEBUG] get(config) INCLUDELOGS="OnFailure"
Notify: [DEBUG] get(config) INCLUDEFILES="yes"
Notify: [DEBUG] get(config) INCLUDESTATS="yes"
Notify: [DEBUG] get(config) ONSUCCESS="yes"
Notify: [DEBUG] get(config) ONFAILURE="yes"
Notify: [DEBUG] get(config) SERVERS="tgram://bot:id/id"
Notify: [DEBUG] get(config) INCLUDEIMAGE="no"
Notify: [DEBUG] get(default) BODY=None
Notify: [DEBUG] get(default) TITLE=None
Notify: [DEBUG] Opened connection to SQLite Database: /share/Download/nzbget/tmp/nzbget/nzbget.db
Notify: [DEBUG] get(config) SERVERS="tgram://bot:id/id"
Notify: [DEBUG] get(system) NZBID="1468"
Notify: NZBParse - NZB-File parsed 0 meta entries
Notify: NZB-File detected: BBC - Trust me I_m a Doctor .nzb.queued
Notify: [DEBUG] NZB-Files located: BBC - Trust me I_m a Doctor .nzb.queued (2018-02-19 19:33:48)
Notify: [DEBUG] Allowed BBC - Trust me I_m a Doctor .nzb.queued (regex)
Notify: [DEBUG] get_files('/share/Download/nzbget/nzb') with 1 filter(s)
Notify: [DEBUG] get(system) NZBDIR="/share/Download/nzbget/nzb"
Notify: [DEBUG] get_files('/share/MD0_DATA/Download/nzbget/tmp') with 1 filter(s)
Notify: [DEBUG] OS: Linux 3.4.6
Notify: [DEBUG] Python v2.7.0
Notify: [DEBUG] Script Mode: postprocess
Executing post-process-script nzbToMedia/Notify.py for BBC - Trust me I_m a Doctor
caronc commented 6 years ago

It will work now. Give it another try (after yet another checkout :wink:).

vledder commented 6 years ago

Did the replace.. you fixed the ssl thinhy indeed. still the API connection failed @ http://nzbget:tegbzn6789@127.0.0.1:6789/xmlrpc error.

Still digging in python versions on my server. One thing I found is that in opt it's 2.7.13 and in usr its 2.7.0. So I assume it picks up from usr. Don't know how to change that. I'll dig some more.

Can I somewhere force in your script to use python from opt location instead of usr?

for what its worth the log:

Post-process-script nzbToMedia/Notify.py for BBC - Trust me I_m a Doctor successful
Notify: [DEBUG] Exiting with return code: 93
Notify: [DEBUG] Telegram Payload: {'text': u'<b>Download&nbsp;Successful</b>\r\n##&nbsp;BBC&nbsp;-&nbsp;Trust&nbsp;me&nbsp;I_m&nbsp;a&nbsp;Doctor&nbsp;##\r\nStatus:&nbsp;SUCCESS/ALL\r\n\r\n###&nbsp;File(s)&nbsp;###\r\n&nbsp;*&nbsp;Trust.Me.Im.A.Doctor.S07E05.WEB-DL.x264-JIVE.mp4&nbsp;(238.31&nbsp;MB)', 'parse_mode': 'HTML', 'chat_id': 'id'}
Notify: [DEBUG] Telegram POST URL: https://api.telegram.org/botbot:id/sendMessage (cert_verify=False)
Notify: [DEBUG] Telegram POST URL: https://api.telegram.org/botbot:id/sendMessage
Notify: [DEBUG] get(config) INCLUDEIMAGE="no"
Notify: [DEBUG] get_files('/share/Download/nzbget/dst/BBC - Trust me I_m a Doctor') with 0 filter(s)
Notify: [DEBUG] Failure Reason: __init__() got an unexpected keyword argument 'context'
Notify: [DEBUG] API connection failed @ http://nzbget:tegbzn6789@127.0.0.1:6789/xmlrpc
Notify: [DEBUG] get(system) CONTROLPASSWORD="tegbzn6789"
Notify: [DEBUG] get(system) CONTROLUSERNAME="nzbget"
Notify: [DEBUG] get(system) CONTROLPORT="6789"
Notify: [DEBUG] get(system) SECUREKEY=""
Notify: [DEBUG] get(system) SECURECERT=""
Notify: [DEBUG] get(system) SECURECONTROL="no"
Notify: [DEBUG] get(config) INCLUDELOGS="OnFailure"
Notify: [DEBUG] get(config) INCLUDEFILES="yes"
Notify: [DEBUG] get(config) INCLUDESTATS="yes"
Notify: [DEBUG] get(config) ONSUCCESS="yes"
Notify: [DEBUG] get(config) ONFAILURE="yes"
Notify: [DEBUG] get(config) SERVERS="tgram://bot:id/id"
Notify: [DEBUG] get(config) INCLUDEIMAGE="no"
Notify: [DEBUG] get(default) BODY=None
Notify: [DEBUG] get(default) TITLE=None
Notify: [DEBUG] Opened connection to SQLite Database: /share/Download/nzbget/tmp/nzbget/nzbget.db
Notify: [DEBUG] get(config) SERVERS="tgram://bot:id/id"
Notify: [DEBUG] get(system) NZBID="1468"
Notify: NZBParse - NZB-File parsed 0 meta entries
Notify: NZB-File detected: BBC - Trust me I_m a Doctor .nzb.queued
Notify: [DEBUG] NZB-Files located: BBC - Trust me I_m a Doctor .nzb.queued (2018-02-20 07:54:03)
Notify: [DEBUG] Allowed BBC - Trust me I_m a Doctor .nzb.queued (regex)
Notify: [DEBUG] get_files('/share/Download/nzbget/nzb') with 1 filter(s)
Notify: [DEBUG] get(system) NZBDIR="/share/Download/nzbget/nzb"
Notify: [DEBUG] get_files('/share/MD0_DATA/Download/nzbget/tmp') with 1 filter(s)
Notify: [DEBUG] OS: Linux 3.4.6
Notify: [DEBUG] Python v2.7.0
Notify: [DEBUG] Script Mode: postprocess
caronc commented 6 years ago

Sorry for taking so long to get back to you!

still the API connection failed @ http://nzbget:tegbzn6789@127.0.0.1:6789/xmlrpc error.

Unfortunately I've reached the limit as to what i can do to make this work for you. Your version of Python is truly broken here. But you're on the right track with trying to point to the newer version instead - which brings me to your next question:

Can I somewhere force in your script to use python from opt location instead of usr?

There are several ways:

  1. Tell your vendor to update their system wide version. This is the absolute best solution. This wouldn't just be impacting you; it would impact anyone with the same device you own. This method will probably having you roll your eyes :wink:; or maybe you've already tried this and got nowhere... so the next option would be...
  2. Replace the bad python executable with the new one. This is extremely hacky so follow the backup steps mentioned first:
    
    # First back up your old version python:
    mv /usr/bin/python /usr/bin/python.orig

Now symbolic link your other version in it's place:

ln -sf /opt/path/to/python /usr/bin/python



I can't stress enough that step no 2 above _might_ work, but there are plenty of reasons why it won't too; so make sure you leave yourself in a position to copy back the old .orig file back over. Again i really stress that option no 1 is the best solution (as annoying, slow and possibly cumbersome it is).

Good luck!  I'll leave this ticket open should you have more questions.
vledder commented 6 years ago

thanks man for the hints! I did some further research and fixed it!

Notify: [DEBUG] Python v2.7.13

For internet legacy troubleshooting QNAP TS-212 python troubles: in usr/bin you'll find a link to where python is installed (mine: /share/MD0_DATA/.qpkg/Python/bin/python) I changed that link (with WinSCP) to where the alternative, more up-to-date python came with (Entware-ng) (mine: /share/MD0_DATA/.qpkg/Entware-ng/bin/python2.7) and that did the trick.

off Topic:

in the message which I receive in Telegram I find a lot of HTML spaces, cant you replace them with normal spaces?

  | Notify:  [DEBUG] Telegram Payload: {'text':  u'<b>Download&nbsp;Successful</b>\r\n##&nbsp;BBC&nbsp;-&nbsp;Trust&nbsp;me&nbsp;I_m&nbsp;a&nbsp;Doctor&nbsp;##\r\nStatus:&nbsp;SUCCESS/ALL\r\n\r\n###&nbsp;Statistics&nbsp;###\r\n&nbsp;*&nbsp;Download&nbsp;Size:&nbsp;258.00&nbsp;MB\r\n&nbsp;*&nbsp;Download&nbsp;Time:&nbsp;00:25:20\r\n&nbsp;*&nbsp;Transfer&nbsp;Speed:&nbsp;173.81&nbsp;KB/s&nbsp;\r\n&nbsp;*&nbsp;Analyse&nbsp;Time:&nbsp;00:00:00\r\n&nbsp;*&nbsp;Repair&nbsp;Time:&nbsp;00:00:00\r\n&nbsp;*&nbsp;Total&nbsp;Archive&nbsp;Preparation&nbsp;Time:&nbsp;00:00:00\r\n&nbsp;*&nbsp;Unarchiving&nbsp;Time:&nbsp;00:05:35\r\n&nbsp;*&nbsp;Total&nbsp;Post-Process&nbsp;Time:&nbsp;00:14:14\r\n&nbsp;*&nbsp;Total&nbsp;Time:&nbsp;00:39:34\r\n\r\n###&nbsp;File(s)&nbsp;###\r\n&nbsp;*&nbsp;Trust.Me.Im.A.Doctor.S07E05.WEB-DL.x264-JIVE.mp4&nbsp;(238.31&nbsp;MB)',  'parse_mode': 'HTML', 'chat_id': '<id>'}
caronc commented 6 years ago

I'm not sure why i escaped all of the HTML characters; i commented out that part of the code; i'm curious why it was there in the first place. :confused:

Edit: As it turns out there was reason. Telegram does not support a heck of a lot of html characters... (barely any at all... just \<b> and \<a> really). Anything outside of the supported characters causes the notice to be rejected by their server. I basically just remove all formatting and ensure content is properly escaped. Anyway... Another crazy thing with their HTML is that they can't interpret the space character (\ ) as you already observed; however they support the others. :roll_eyes: I added a small hack to just eliminate spaces and substitute them back as... well spaces... (hope that makes sense).

Anyway... as always, I'd be interested in your feedback. I'll also set my system to report Telegram so i can observe the output and tweak any unusual formatting as necessary.

vledder commented 6 years ago

just copied the latest source but the HTML spaces aren't replaced so the replacing is not yet working:

Notify: [DEBUG] Telegram Payload: {'text': u'<b>Download Successful</b>\r\n## BBC -&nbsp;Trust&nbsp;me&nbsp;I_m&nbsp;a&nbsp;Doctor&nbsp;##\r\nStatus:&nbsp;SUCCESS/ALL\r\n\r\n###&nbsp;Statistics&nbsp;###\r\n&nbsp;*&nbsp;Download&nbsp;Size:&nbsp;258.00&nbsp;MB\r\n&nbsp;*&nbsp;Download&nbsp;Time:&nbsp;00:25:20\r\n&nbsp;*&nbsp;Transfer&nbsp;Speed:&nbsp;173.81&nbsp;KB/s&nbsp;\r\n&nbsp;*&nbsp;Analyse&nbsp;Time:&nbsp;00:00:00\r\n&nbsp;*&nbsp;Repair&nbsp;Time:&nbsp;00:00:00\r\n&nbsp;*&nbsp;Total&nbsp;Archive&nbsp;Preparation&nbsp;Time:&nbsp;00:00:00\r\n&nbsp;*&nbsp;Unarchiving&nbsp;Time:&nbsp;00:05:35\r\n&nbsp;*&nbsp;Total&nbsp;Post-Process&nbsp;Time:&nbsp;00:14:46\r\n&nbsp;*&nbsp;Total&nbsp;Time:&nbsp;00:40:06\r\n\r\n###&nbsp;File(s)&nbsp;###\r\n&nbsp;*&nbsp;Trust.Me.Im.A.Doctor.S07E05.WEB-DL.x264-JIVE.mp4&nbsp;(238.31&nbsp;MB)', 'parse_mode': 'HTML', 'chat_id': '<id>'}

I also saw that in Notify options you can sent an image. According Telegram's api its supported but did you implemented it for telegram? Just wondering if it was a bug yes or no.

caronc commented 6 years ago

Okay, we'll try this one more time then; as per your other question. i didn't look into images because i think they're sent separately (they can't be sent in the same notification - or at least i don't think they can be).

Do you want to see an image come through just to have the text follow in a second message? Might seem kind of noisy... thoughts?

vledder commented 6 years ago

yup! that did the trick. Looking all good and shiny now! thx! 👍

For the image thoughts: if its an image without any header/title its not that disturbing actually, since telegram messenger shows messages close to each other so an user can relate real quick. Of course the user can disable it in settings to their liking too. So I'd say why not, but hey it's your pet project :)

caronc commented 6 years ago

I'll put this one on hold until the weekend, but will keep you posted.