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.
Pre-queue script not running
Forum rules
Help us help you:
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.
Re: Pre-queue script not running
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?
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
Re: Pre-queue script not running
Thanks for the welcome.
It's running on windows 10. I did select the script in switches.
Here is the script:
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.
It's running on windows 10. I did select the script in switches.
Here is the script:
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.
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)
sys.exit(0)
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.
Re: Pre-queue script not running
Your script works fine here on Debian 9.5 and Python 2.7.13
Suggest you check the script indentation. Python requires indentation to be correct. Your script should be "shaped" like this:
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):
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)
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
Re: Pre-queue script not running
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.
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.
Re: Pre-queue script not running
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.
Re: Pre-queue script not running
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.
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
Re: Pre-queue script not running
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.
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
Re: Pre-queue script not running
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.
Good point , although that line should not be indented.OneCD wrote: ↑September 25th, 2018, 10:02 pmSuggest you check the script indentation. Python requires indentation to be correct.Code: Select all
[...] autofile.close() [...]
Re: Pre-queue script not running
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
Re: Pre-queue script not running
So I had already tried this by pointing to various other locations directly and none helped.
Re: Pre-queue script not running
Ok I did this and what I get is this: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.
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.
Re: Pre-queue script not running
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:
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.
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
Re: Pre-queue script not running
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+")
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
Re: Pre-queue script not running
Thanks safihre, I guess I thought I didn't need the escapes because it was inside the literal "" but that makes total sense.