Pre-queue script not running

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
radadar
Newbie
Newbie
Posts: 8
Joined: September 25th, 2018, 8:31 pm

Pre-queue script not running

Post by radadar »

I've written a pre-queue script in python and it doesn't seem to want to execute. I have ".py" added to PATHEXT and I have python installed on the computer that the SABnzbd is running on. I know that the script isn't being executed because it will make a log file on execution and this is done when running the script directly but not when done via SABnzbd.

Any ideas why it won't run? Thanks.
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: Pre-queue script not running

Post by OneCD »

Hi and welcome to the forum. :)

Did you select it in SABnzbd Config -> Switches -> Queue -> Pre-queue user script?

Is this on Windows? Linux?

Can you post your script?
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
radadar
Newbie
Newbie
Posts: 8
Joined: September 25th, 2018, 8:31 pm

Re: Pre-queue script not running

Post by radadar »

Thanks for the welcome.

It's running on windows 10. I did select the script in switches.

Here is the script:

import sys

acpt = 1
autofile = open("AutoNames.txt","a+")

try:
(scriptname, nzbname, postprocflags, category, script, prio, downloadsize, grouplist, showname, season, episodenumber, episodename) = sys.argv
downloadsize = int(downloadsize)
except:
sys.exit(1)

if category == "adultauto":
autofile.write(nzbname + "\n")

autofile.close()

print(acpt)
print
print
print
print
print
print
sys.exit(0)
Right now all the script does is writes a log of nzbs from a category to a log file. Eventually my plan is to have it reference back to the log to prevent similar files from (but not exact duplicates) from downloading.

I'm very new to python and scripting so there could be errors I'm sure, but direct execution of the script (via explorer) creates the AutoNames.txt file and adding a nzb to SABnzbd doesn't.

Thanks.
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: Pre-queue script not running

Post by OneCD »

Your script works fine here on Debian 9.5 and Python 2.7.13 ;D

Suggest you check the script indentation. Python requires indentation to be correct. Your script should be "shaped" like this:

Code: Select all

import sys

acpt = 1
autofile = open("AutoNames.txt","a+")

try:
	(scriptname, nzbname, postprocflags, category, script, prio, downloadsize, grouplist, showname, season, episodenumber, episodename) = sys.argv
	downloadsize = int(downloadsize)
except:
	sys.exit(1)

if category == "adultauto":
	autofile.write(nzbname + "\n")

	autofile.close()

print(acpt)
print
print
print
print
print
print
sys.exit(0)
Also, because this sample script reads the downloadsize variable, you'll need to assign a value to it when testing, or else remove that line from your script. Ensure all other arguments are specified, even if they are empty. In BASH, we can use two single quotes for this (they look like double quotes - they're not):

Code: Select all

$ ./radadar-prequeue.py nzbname '' adultauto '' '' 50000 '' '' '' '' ''
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
radadar
Newbie
Newbie
Posts: 8
Joined: September 25th, 2018, 8:31 pm

Re: Pre-queue script not running

Post by radadar »

Thanks for all the help here. Couple questions if you don't mind me asking.

The indentation difference that I see in your code is only on the autofile.close(), correct? Wouldn't indenting that cause it to only execute if the above if statement is true?

Also, I'm taking it to mean that that I should make sure there is a null in the output arguments not the input. I believe in python I should have it be print("") but again I'm very new at all this.

I'll give your modified code a try.

Thanks.
radadar
Newbie
Newbie
Posts: 8
Joined: September 25th, 2018, 8:31 pm

Re: Pre-queue script not running

Post by radadar »

So I tried the changes to the script and it still wouldn't execute. I think there is still something wrong with how SAB is executing the script because I also tried making a simple bat file that opens notepad (start notepad) just to make sure I could execute something and that worked fine. Even if I just write a very simple python script that writes "hello world" to a file it still doesn't execute.
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: Pre-queue script not running

Post by OneCD »

As I’m not running this in a Windows environment, I’m not able to suggest anything else. Sorry. :(

Hopefully, another forum member can assist you further.
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
User avatar
safihre
Administrator
Administrator
Posts: 5338
Joined: April 30th, 2015, 7:35 am
Contact:

Re: Pre-queue script not running

Post by safihre »

I would enable Debug logging in the Status and Interface settings window.
Then try again to add an NZB (in a paused queue).
Then download the log by clicking Show Logging in the Status and Interface settings window.
There you can see, near the end what the output of the script was.
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
User avatar
jcfp
Release Testers
Release Testers
Posts: 986
Joined: February 7th, 2008, 12:45 pm

Re: Pre-queue script not running

Post by jcfp »

radadar wrote: September 25th, 2018, 9:12 pm

Code: Select all

autofile = open("AutoNames.txt","a+")
Using a relative filename here may be the problem. It assumes that the script has a work dir, that it is always the same, and writable at that. That might be true in your tests but not when run by sab.
OneCD wrote: September 25th, 2018, 10:02 pmSuggest you check the script indentation. Python requires indentation to be correct.

Code: Select all

[...]
	autofile.close()
[...]
Good point , although that line should not be indented.
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: Pre-queue script not running

Post by OneCD »

jcfp wrote: September 26th, 2018, 6:42 amGood point , although that line should not be indented.
You're right. My Python coding is very rusty. :-[
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
radadar
Newbie
Newbie
Posts: 8
Joined: September 25th, 2018, 8:31 pm

Re: Pre-queue script not running

Post by radadar »

jcfp wrote: September 26th, 2018, 6:42 am Using a relative filename here may be the problem. It assumes that the script has a work dir, that it is always the same, and writable at that. That might be true in your tests but not when run by sab.
So I had already tried this by pointing to various other locations directly and none helped.
radadar
Newbie
Newbie
Posts: 8
Joined: September 25th, 2018, 8:31 pm

Re: Pre-queue script not running

Post by radadar »

safihre wrote: September 26th, 2018, 1:53 am I would enable Debug logging in the Status and Interface settings window.
Then try again to add an NZB (in a paused queue).
Then download the log by clicking Show Logging in the Status and Interface settings window.
There you can see, near the end what the output of the script was.
Ok I did this and what I get is this:

Code: Select all

2018-09-26 19:32:52,477::INFO::[newsunpack:2348] Pre-queue script returns 1 and output=
'"python"' is not recognized as an internal or external command,
operable program or batch file.
Now I've noticed that on my version of python (3.6) it puts a root accessible interpreter in the windows folder but it names it "py" not "python". Could this be the problem? Is SAB trying to do a command line call but thinking the program to call is "python" and not "py"?
radadar
Newbie
Newbie
Posts: 8
Joined: September 25th, 2018, 8:31 pm

Re: Pre-queue script not running

Post by radadar »

OK thanks everyone for the help I think I figured out my big problem anyways. Looks like all I needed to do was rename the interpreter from "py" to "python".

I did actually run across a permissions problem as well as JCFP had assumed.

I tried pointing directly to a folder but I got this error:

Code: Select all

2018-09-26 19:49:07,844::INFO::[newsunpack:2348] Pre-queue script returns 1 and output=
  File "Y:\<USERNAME>\Documents\0_Misc\AutoHotKey Scripts\SABnzbd\preque.py", line 4
    autofile = open("C:\Users\<USERNAME>\Documents\AutoNames.txt","a+")
                   ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
If any Python wizard happens to know what I got wrong here I'd be very appreciative but since this seems to be a python issue not a sab issue I'll try stack exchange.
User avatar
safihre
Administrator
Administrator
Posts: 5338
Joined: April 30th, 2015, 7:35 am
Contact:

Re: Pre-queue script not running

Post by safihre »

The \ is an escape character, for example for special unicode characters but also for simple things like "
So you should "escape" your escape character:
autofile = open("C:\\Users\\<USERNAME>\\Documents\\AutoNames.txt","a+")
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
radadar
Newbie
Newbie
Posts: 8
Joined: September 25th, 2018, 8:31 pm

Re: Pre-queue script not running

Post by radadar »

Thanks safihre, I guess I thought I didn't need the escapes because it was inside the literal "" but that makes total sense.
Post Reply