zSeriesGuy / Tautulli

A Python based monitoring and tracking tool for Plex Media Server.
http://tautulli.com
GNU General Public License v3.0
27 stars 9 forks source link

Custom Script "KillStream error" #27

Closed luisvillalobos528 closed 4 years ago

luisvillalobos528 commented 4 years ago

Hi I have a custom script that has an error, It's a killstream like one of the closed issue's but instead of limit user streams to one IP, I want to kill stream if "User X" is "Transcoding" everything works in normal tautulli but in multi server one doesn't

https://github.com/blacktwin/JBOPS/tree/master/killstream#kill-transcodes

Maybe you could look into it and fix it like you did for the stream one IP script. Please

Version: Tautulli: V4.0.09 PMS: 1.18.7.2457-77cb9455c | Linux

Operating system:

Server: Ubuntu 16.04.6 LTS Server: Ubuntu 18.04.2 LTS Python version: 3.8

luisvillalobos528 commented 4 years ago

Sorry forgot to paste what I think is the error:

2020-02-28 02:15:12 - DEBUG :: Thread-2 : Tautulli NotificationHandler :: Custom condition evaluated to 'True'. Conditions: [True, True, True]. 2020-02-28 02:15:12 - INFO :: Thread-2 : Tautulli NotificationHandler :: Preparing notification for notifier_id 1. 2020-02-28 02:15:12 - ERROR :: Thread-2 : Tautulli NotificationHandler :: Unable to parse custom script arguments: 'str' object has no attribute 'decode'. Using fallback. 2020-02-28 02:15:12 - DEBUG :: Thread-2 : Tautulli Notifiers :: Trying to run notify script, action: play, arguments: []2020-02-28 02:15:12 - DEBUG :: Thread-2 : Tautulli Notifiers :: Full script is: ['python', b'C:\ProgramData\Tautulli\Scripts\JBOPS\killstream\kill_stream.py'] 2020-02-28 02:15:12 - DEBUG :: Thread-2 : Tautulli Notifiers :: Executing script in a new thread. 2020-02-28 02:15:12 - ERROR :: Thread-19 : IP Checker :: Bad IP or hostname provided. 2020-02-28 02:15:12 - ERROR :: Thread-19 : IP Checker :: Bad IP or hostname provided. 2020-02-28 02:15:12 - ERROR :: Thread-19 : IP Checker :: Bad IP or hostname provided. 2020-02-28 02:15:12 - ERROR :: Thread-19 : IP Checker :: Bad IP or hostname provided. 2020-02-28 02:15:12 - ERROR :: Thread-19 : IP Checker :: Bad IP or hostname provided. 2020-02-28 02:15:12 - ERROR :: Thread-19 : IP Checker :: Bad IP or hostname provided. 2020-02-28 02:15:12 - ERROR :: Thread-19 : IP Checker :: Bad IP or hostname provided. 2020-02-28 02:15:12 - ERROR :: Thread-19 : IP Checker :: Bad IP or hostname provided. 2020-02-28 02:15:12 - ERROR :: Thread-19 : Uncaught exception: Traceback (most recent call last): File "C:\ProgramData\Tautulli\plexpy\logger.py", line 341, in new_run

zSeriesGuy commented 4 years ago

Try this. Edit the kill_stream.py code and on line 105, remove the decode so that the line is return arg.encode('UTF-8')

The JBOPS scripts were written for the official Tautulli which is still Python 2. Note that this kill_stream script does not handle the multiple servers. It should still work. But one potential side effect is that if there are streams on multiple servers with the same session ID, this script will probably kill both of them. It is possible to have the same session ID on multiple servers. I may try to address that in a future update to my code.

luisvillalobos528 commented 4 years ago

Am getting this error now 2020-02-29 03:02:23 - DEBUG :: WebSocket-Asteria : Tautulli ActivityHandler :: Asteria: Session 12 has changed transcode decision. 2020-02-29 03:02:23 - DEBUG :: Thread-1 : Tautulli NotificationHandler :: Checking custom notification conditions for notifier_id 1. 2020-02-29 03:02:23 - DEBUG :: Thread-1 : Tautulli NotificationHandler :: Custom condition evaluated to 'True'. Conditions: [True, True]. 2020-02-29 03:02:23 - INFO :: Thread-1 : Tautulli NotificationHandler :: Preparing notification for notifier_id 1. 2020-02-29 03:02:23 - ERROR :: Thread-1 : Tautulli NotificationHandler :: Unable to parse custom script arguments: 'str' object has no attribute 'decode'. Using fallback. 2020-02-29 03:02:23 - DEBUG :: Thread-1 : Tautulli Notifiers :: Trying to run notify script, action: change, arguments: [] 2020-02-29 03:02:23 - DEBUG :: Thread-1 : Tautulli Notifiers :: Full script is: ['python', b'C:\ProgramData\Tautulli\Scripts\JBOPS\killstream\kill_stream.py'] 2020-02-29 03:02:23 - DEBUG :: Thread-1 : Tautulli Notifiers :: Executing script in a new thread. 2020-02-29 03:02:23 - ERROR :: Thread-18 : IP Checker :: Bad IP or hostname provided. 2020-02-29 03:02:23 - ERROR :: Thread-18 : IP Checker :: Bad IP or hostname provided. 2020-02-29 03:02:23 - ERROR :: Thread-18 : IP Checker :: Bad IP or hostname provided. 2020-02-29 03:02:23 - ERROR :: Thread-18 : IP Checker :: Bad IP or hostname provided. 2020-02-29 03:02:23 - ERROR :: Thread-18 : IP Checker :: Bad IP or hostname provided. 2020-02-29 03:02:23 - ERROR :: Thread-18 : IP Checker :: Bad IP or hostname provided. 2020-02-29 03:02:23 - ERROR :: Thread-18 : IP Checker :: Bad IP or hostname provided. 2020-02-29 03:02:23 - ERROR :: Thread-18 : IP Checker :: Bad IP or hostname provided. 2020-02-29 03:02:23 - ERROR :: Thread-18 : Uncaught exception: Traceback (most recent call last): File "C:\ProgramData\Tautulli\plexpy\logger.py", line 341, in new_run old_run(*args, *kwargs) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\threading.py", line 870, in run self._target(self._args, **self._kwargs) File "C:\ProgramData\Tautulli\plexpy\notifiers.py", line 3067, in run_script env=env) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64qbz5n2kfra8p0\lib\subprocess.py", line 800, in init__ restore_signals, start_new_session) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64qbz5n2kfra8p0\lib\subprocess.py", line 1148, in _execute_child args = list2cmdline(args) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64qbz5n2kfra8p0\lib\subprocess.py", line 555, in list2cmdline needquote = (" " in arg) or ("\t" in arg) or not arg TypeError: a bytes-like object is required, not 'str'

Traceback (most recent call last): File "C:\ProgramData\Tautulli\plexpy\logger.py", line 341, in new_run old_run(*args, *kwargs) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\threading.py", line 870, in run self._target(self._args, **self._kwargs) File "C:\ProgramData\Tautulli\plexpy\notifiers.py", line 3067, in run_script env=env) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64qbz5n2kfra8p0\lib\subprocess.py", line 800, in init__ restore_signals, start_new_session) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64qbz5n2kfra8p0\lib\subprocess.py", line 1148, in _execute_child args = list2cmdline(args) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64qbz5n2kfra8p0\lib\subprocess.py", line 555, in list2cmdline needquote = (" " in arg) or ("\t" in arg) or not arg TypeError: a bytes-like object is required, not 'str'

zSeriesGuy commented 4 years ago

I believe I have this resolved now. The resolution needed changes in my code. Install the latest release of my code. Also, in the killstream.py script on line 105, change it to: if isinstance(arg, str): return arg else: return arg.decode(TAUTULLI_ENCODING).encode('UTF-8')

luisvillalobos528 commented 4 years ago

OK I did that new code from you and edited the killstream.py to what u told me and got this now: 2020-03-02 00:11:34 - DEBUG :: WebSocket-Asteria : Tautulli ActivityHandler :: Asteria: Session 23 has changed transcode decision. 2020-03-02 00:11:35 - DEBUG :: Thread-2 : Tautulli NotificationHandler :: Checking custom notification conditions for notifier_id 1. 2020-03-02 00:11:35 - DEBUG :: Thread-2 : Tautulli NotificationHandler :: Custom condition evaluated to 'True'. Conditions: [True, True]. 2020-03-02 00:11:35 - INFO :: Thread-2 : Tautulli NotificationHandler :: Preparing notification for notifier_id 1. 2020-03-02 00:11:35 - DEBUG :: Thread-2 : Tautulli Notifiers :: Trying to run notify script, action: change, arguments: ['--jbop', 'stream', '--username', 'totomix07', '--sessionId', 'ofitc7nasp1mcfrhcwkn2vs4', '--killMessage', 'Transcoding streams are not allowed.'] 2020-03-02 00:11:35 - DEBUG :: Thread-2 : Tautulli Notifiers :: Full script is: ['python', 'C:\Tautulli\Scripts\JBOPS\killstream\kill_stream.py', '--jbop', 'stream', '--username', 'totomix07', '--sessionId', 'ofitc7nasp1mcfrhcwkn2vs4', '--killMessage', 'Transcoding streams are not allowed.'] 2020-03-02 00:11:35 - DEBUG :: Thread-2 : Tautulli Notifiers :: Executing script in a new thread. 2020-03-02 00:11:35 - ERROR :: Thread-19 : Uncaught exception: Traceback (most recent call last): File "C:\Tautulli\plexpy\logger.py", line 341, in new_run old_run(*args, *kwargs) File "C:\Python37\lib\threading.py", line 870, in run self._target(self._args, **self._kwargs) File "C:\Tautulli\plexpy\notifiers.py", line 3067, in run_script env=env) File "C:\Python37\lib\subprocess.py", line 800, in init restore_signals, start_new_session) File "C:\Python37\lib\subprocess.py", line 1207, in _execute_child startupinfo) TypeError: CreateProcess() argument 8 must be str or None, not bytes

Traceback (most recent call last): File "C:\Tautulli\plexpy\logger.py", line 341, in new_run old_run(*args, *kwargs) File "C:\Python37\lib\threading.py", line 870, in run self._target(self._args, **self._kwargs) File "C:\Tautulli\plexpy\notifiers.py", line 3067, in run_script env=env) File "C:\Python37\lib\subprocess.py", line 800, in init restore_signals, start_new_session) File "C:\Python37\lib\subprocess.py", line 1207, in _execute_child startupinfo) TypeError: CreateProcess() argument 8 must be str or None, not bytes

zSeriesGuy commented 4 years ago

Strange. I noticed that the change to kill_stream.py that I pasted into this issue left shifted everything. The code should be indented. Is it possible that is the issue? This is how it should look. What it should be doing is if the arg is already in string format, just return it without attempting to decode/encode it. If your code is as pictured, try just changing line 105 to just return arg without the if.

image

luisvillalobos528 commented 4 years ago

I don't understand what you want me to do next, heres the actual lines i got:

def arg_decoding(arg): """Decode args, encode UTF-8""" if isinstance(arg, str): return arg else: return arg.decode(TAUTULLI_ENCODING).encode('UTF-8')

let me know what should it look like?

zSeriesGuy commented 4 years ago

Are you able to see the picture of the code in my last post? That was a screen shot from kill_stream.py at line 105. The code should be indented. I am attaching my copy of kill_stream.py. Unzip this and see if that works. kill_stream.zip

luisvillalobos528 commented 4 years ago

I just downloaded your zip and replaced my file and this is what I get:

2020-03-02 17:18:09 - DEBUG :: Thread-1 : Tautulli NotificationHandler :: Custom condition evaluated to 'True'. Conditions: [True, True]. 2020-03-02 17:18:09 - INFO :: Thread-1 : Tautulli NotificationHandler :: Preparing notification for notifier_id 1. 2020-03-02 17:18:09 - DEBUG :: Thread-1 : Tautulli Notifiers :: Trying to run notify script, action: change, arguments: ['--jbop', 'stream', '--username', 'totomix07', '--sessionId', '07k76dvg8ki7udbfkjsyzrru', '--killMessage', 'Transcoding streams are not allowed.'] 2020-03-02 17:18:09 - DEBUG :: Thread-1 : Tautulli Notifiers :: Full script is: ['python', 'C:\Tautulli\Scripts\JBOPS\killstream\kill_stream.py', '--jbop', 'stream', '--username', 'totomix07', '--sessionId', '07k76dvg8ki7udbfkjsyzrru', '--killMessage', 'Transcoding streams are not allowed.'] 2020-03-02 17:18:09 - DEBUG :: Thread-1 : Tautulli Notifiers :: Executing script in a new thread. 2020-03-02 17:18:09 - ERROR :: Thread-17 : Uncaught exception: Traceback (most recent call last): File "C:\Tautulli\plexpy\logger.py", line 341, in new_run old_run(*args, *kwargs) File "C:\Python37\lib\threading.py", line 870, in run self._target(self._args, **self._kwargs) File "C:\Tautulli\plexpy\notifiers.py", line 3067, in run_script env=env) File "C:\Python37\lib\subprocess.py", line 800, in init restore_signals, start_new_session) File "C:\Python37\lib\subprocess.py", line 1207, in _execute_child startupinfo) TypeError: CreateProcess() argument 8 must be str or None, not bytes

Traceback (most recent call last): File "C:\Tautulli\plexpy\logger.py", line 341, in new_run old_run(*args, *kwargs) File "C:\Python37\lib\threading.py", line 870, in run self._target(self._args, **self._kwargs) File "C:\Tautulli\plexpy\notifiers.py", line 3067, in run_script env=env) File "C:\Python37\lib\subprocess.py", line 800, in init restore_signals, start_new_session) File "C:\Python37\lib\subprocess.py", line 1207, in _execute_child startupinfo) TypeError: CreateProcess() argument 8 must be str or None, not bytes

zSeriesGuy commented 4 years ago

Update to the release I just published. Turns out I was testing with Python 3.8 and you are using Python 3.7. There was a change in Py3.8 that allowed bytes for the CWD in the script process call.

luisvillalobos528 commented 4 years ago

Works Now!!! Wow Thanks so much for your help as always, now I can ditch the python 2 forever :)