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
128 stars 15 forks source link

Notification script returned exit code 1 and output "Traceback (most recent call last) #72

Closed SuissoNaBisso9 closed 2 years ago

SuissoNaBisso9 commented 4 years ago

:question: Question

hey ! trying to set up the notify script on SABnzbd for Discord.

Well installed all files on home/user/SABnzbd/scripts Did a chmod +x to make them executable

Also in "parameters" field I've set my Discord webhook URL.

But on SABnzbd when triggering the test notification i get the following error : Notification script returned exit code 1 and output "Traceback (most recent call last): File "/home/suissonabisso/SABnzbd/scripts/Notify.py", line 174, in from nzbget import SCRIPT_MODE ImportError: No module named nzbget "

What I've missed ?

Thank you !

caronc commented 4 years ago

You're just missing the plugins that this script relies on:

pip install -r requirements.txt

#alternatively this should work too:
pip install pynzbget
SuissoNaBisso9 commented 4 years ago

Actually I did install all requirements and tested this 'pip install pynzbget' and it also said requirements already satisfied. But still SABnzdbd is returning same error code

caronc commented 4 years ago

Strange, is SABnzbd running in a Docker container? These commands need to be ran in there if so.

What is your os? Also, what version of Python and SABnzbd are you using?

SuissoNaBisso9 commented 4 years ago

No docker and using ubuntu 18.04 SAbnzbd version : 3.1.0RC3 [6aef50d] Python : python 3.8.2

caronc commented 3 years ago

I wonder if this is an issue with multiple python versions. Can you try same pip commands, but use pip3 instead?

SuissoNaBisso9 commented 3 years ago

Already did too, all requirements satisfied as well

caronc commented 3 years ago

The last few things you could try is manually running the script yourself to see if you get the same error:

# Just to test things:
python /path/to/sabnzbd/sabnzbd-notify.py complete 'Hello' 'World' <Apprise URL here>

If that works then there is something unique about your SABnzbd installation; the environment it runs in is completely different the the one you're in when you call the script. Perhaps a Python virtual env?

If that doesn't work, then the problem gets a bit easier to solve because at least it's reproducible

SuissoNaBisso9 commented 3 years ago

So just tested and getting the same error code : image

caronc commented 3 years ago

Sorry for the long delay; It seems like your pip repository got damaged or corrupted some how. I would just uninstall pynzbget and put it back in. Hopefully the system will pick it up then:

pip uninstall pynzbget
pip install pynzbget
SuissoNaBisso9 commented 3 years ago

Hey Just tried that but still getting the same error message, both from SABnzbd and by testing directly in CLI

caronc commented 3 years ago

that's really weird, there is definitely something wrong with your environment :slightly_frowning_face: .

i verified the script works correctly by doing the following myself:

# create a new virtual environment to test with:
python3 -m venv test-nzb-notfify

# Change into our new directory
cd  test-nzb-notfify

# Activate our virtual environment
source bin/activate

# Install pynzbget
pip install pynzbget

# test that the environment variables are importable:
python -c "from nzbget import SCRIPT_MODE" && echo "OKAY" || or echo "Fail"

The above outputs OKAY every-time for me; i get no import error. If installation the library and reloading it doesn't work then there is something that is obstructing your Python library of installed packages.

Another possibility is there is another Python library called nzbget installed into your library and when your system calls from nzbget import SCRIPT_MODE it can't find it.

You could check inside your SABnzbd installation directory and make sure there is no directory called nzbget with an __init__.py file in it... OR a file called nzbget.py. The other thing you could do (to test this theory) is open up a python console (just type python) and do the following:

# in a python terminal:
import nzbget

# If the above does not give you an error then something was found and imported...

# Test that it is a module:
print(type(nzbget))
# expect output like: <class 'module'>

# Now find out where this module came from:
print(nzbget.__file__)

# Verify that the path that is outputed is indeed where you installed pynzbget;  My guess is this
# is not valid package.  Or if it is (that's fine too), but it isn't the one you want :slightly_smiling_face: 
SuissoNaBisso9 commented 3 years ago

Hi

Thanks for chekcing further

So actually looking in my SABnzbd directory I found another file 'init.py' First one is there /home/user/SABnzbd/sabnzbd/init.py the second is the one from your script here /home/user/SABnzbd/scripts/Notify/init.py

Then I aslo ran a python terminal with first command and it gave me this :

(1:355)# python Python 2.7.17 (default, Sep 30 2020, 13:38:04) [GCC 7.5.0] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import nzbget Traceback (most recent call last): File "", line 1, in ImportError: No module named nzbget

caronc commented 3 years ago

So i can see one problem already; up above, you said:

SAbnzbd version : 3.1.0RC3 [6aef50d] Python : python 3.8.2

SABnzbd requries Python v3. so this all makes sense. But your last comment shows you running the test using Python v2.7 (which operates in a completely different realm and requires a separate pip installation for it).

In a situation where you have both Python v2 and v3, you need to use pip3 or pip to separate the calls. You also need to use the binary python3 and python (for v2 references).

Python 2.7.17 (default, Sep 30 2020, 13:38:04)

Is it possible that pynzbget is properly installed in your Python 3 environment and both you and your SABnzbd is running in a Python 2 environment? Another issue that can cause problems is stale .pyc files. You could try stopping SABnzbd and removing the .pyc files if any were created (this is safe; don't worry). Something like:

find /path/to/your/sabnzbd/installation -type f -name '*.pyc' --delete
SuissoNaBisso9 commented 3 years ago

Not sure I'm doing this right ? image

SuissoNaBisso9 commented 3 years ago

and yes for Python that's weir, but SABnzbd says I'm running this : image

I'm running the seedbox script Quickbox Pro FYI, and they use different python version as I understood, for example for Tautulli I had to manually change the config file to run with Python 3 and then run some scripts.

caronc commented 3 years ago

So the catch is, you can't just change to use the python 3 binary you have installed on the Quickbox Pro setup. You need to change your environment as well so your virtually sitting in the same world as SABnzbd is.

I don't know much about Quickbox Pro or how SABnzbd gets installed into it with a custom version of Python. You'll need to mimic it's environment variables and stuff since entries like PYTHONPATH for example can cause your application to look in one location for all of it's packages while you install it in another. Do you have the instructions or tricks you did to install SABnzbd? Does Quickbox just run natively on a server? Or is it like managing docker containers for you? It might be setting up virtual environments so that some applications don't step on others?

SuissoNaBisso9 commented 3 years ago

Hi

Thanks for checking all this, I'll share this case with Quickbox Pro support team because honestly I don't have so much information abaout hw it works etc... Will keep you updated if I have some progress.

Thank you for the support again !

Squiggles4321 commented 3 years ago

Hey,

If you have python3 on your system as well, but python2 is still the system default just edit sabnzbd-notify.py and Notify.py and change:

!/usr/bin/env python

to

!/usr/bin/env python3

It is what I had to do in my multi-python system. Working fine now when it invokes python3.

-Squigs

SuissoNaBisso9 commented 3 years ago

Hey @Squiggles4321 Just tried that but i'm stil getting the same errors as usual. Will have to check further with Quickbox Pro support team

Thanks !

Squiggles4321 commented 3 years ago

Very specific to your environment then. Good luck.

-Squigs

caronc commented 2 years ago

I'm closing this ticket off; unfortunately it's 100% related to the python installation and it's configured environment