Execute plugin won't run python script

General support for problems installing or using Deluge
Post Reply
bengalih
Leecher
Leecher
Posts: 60
Joined: Fri Feb 14, 2014 3:31 am

Execute plugin won't run python script

Post by bengalih »

I wrote a python script which leverages the RPC client to do some actions.
The script works perfect when run alone.

When I try to run it with Execute (on torrent add), it doesn't run.
According to the logs, it is executed. I see something like this:

Code: Select all

19:43:25 [DEBUG   ][deluge_execute.core           :61  ] Running commands for added
19:43:25 [DEBUG   ][deluge_execute.core           :61  ] Running C:\programdata\scripts\deluge\deluge-test.bat with args: [b'6f4df3cadd0a13275210b86c9828b99f70c96155', b'TEST-TORRENT', b'F:\\queue']
I have also seen issues like this:

Code: Select all

Event handler TorrentAddedEvent failed in <function Core.enable.<locals>.create_event_handler.<locals>.event_handler at 0x000002AD36648550> with exception 'C:\\programdata\\scripts\\deluge\\deluge-test.py' is neither a Windows executable, nor a script with a shebang line
Now I have tried this by just running the python script directly in the Execute command line:

Code: Select all

c:\programdata\scripts\deluge\deluge-test.py
I have also tried like this:

Code: Select all

python c:\programdata\scripts\deluge\deluge-test.py
I have also tried to write a .bat file wrapper. When I run the bat file manually with a torrent ID argument it runs properly logs itself, runs the python and the python logs, so I know it all runs, but when I try to run it via execute, I can never get the .py file to run no matter what I try.

This has to be something easy, but poorly documented and I can't figure it out.

thanks.

EDIT: The log snippets above are from different runs, sometimes using the .bat wrapper, sometimes using the .py straight. Usually with the py I get different errors, with the .bat I don't get the errors, but the .py script which is called from the .bat doesn't run even though it does manually. I hard coded all paths so the fact that log files don't get created show its not running at all.
bengalih
Leecher
Leecher
Posts: 60
Joined: Fri Feb 14, 2014 3:31 am

Re: Execute plugin won't run python script

Post by bengalih »

I discovered that the issue was that python was in the PATH for my user, but not in the path for the deulge daemon and so it was never properly calling python to run the script.

I initially still needed to use the .bat wrapper and specify the full path to python.exe, but then discovered I could add this at the top of my python script:

Code: Select all

#!path to python.exe
such as:

Code: Select all

#!C:\Users\myuser\AppData\Local\Programs\Python\Python312\python.exe
This allowed the .py to be called and executed directly from the Execute plugin.
Post Reply