Custom script "exited with code: 1" error ( script from sickbeard_mp4_automator on macOS Mojave)

Sonarr version (exact version):

Mono version (if Sonarr is not running on Windows):

macOS 10.14.5

Debug logs:

Description of issue:
I’m trying to configure the sickbeard_mp4_automator script with Sonarr v3. The scripts perfectly with Sonarr version 2, but fails with a “Script exited with code: 1” in Sonarr v3.

19-7-5 13:34:53.4|Debug||Starting /Users/USER/Scripts/sickbeard_mp4_automator/ 
19-7-5 13:34:53.5|Error||Traceback (most recent call last):
19-7-5 13:34:53.5|Error||  File "/Users/USER/Scripts/sickbeard_mp4_automator/", line 5, in <module>
19-7-5 13:34:53.5|Error||    import requests
19-7-5 13:34:53.5|Error||ImportError: No module named requests
19-7-5 13:34:53.5|Debug|CustomScript|Executed external script: /Users/USER/Scripts/sickbeard_mp4_automator/ - Status: 1
19-7-5 13:34:53.5|Debug|CustomScript|Script Output: 
7/5/2019 8:34:53 PM - Error - Traceback (most recent call last):
7/5/2019 8:34:53 PM - Error -   File "/Users/USER/Scripts/sickbeard_mp4_automator/", line 5, in <module>
7/5/2019 8:34:53 PM - Error -     import requests
7/5/2019 8:34:53 PM - Error - ImportError: No module named requests
19-7-5 13:34:53.6|Warn|SonarrErrorPipeline|Invalid request Validation failed: 
 -- Script exited with code: 1
19-7-5 13:34:53.6|Debug|Api|[POST] /api/v3/notification/test: 400.BadRequest (228 ms)

I’ve confirmed that python is working correctly and that the requests module is installed properly. And as I said, the script works fine in Sonarr v2. Any ideas or clues as to what’s wrong?

I’ve noticed that Sonarr v2 has a two separate entry areas, one for “Path” and one for “Arguments”, in the custom script area, whereas Sonarr v3 only has one. Could that be why the script is failing because Sonarr v3 isn’t getting right right path?

In v2, the path for python would be the python executable (at least most often) and the arguments would tell the executable which script to execute.

This approach was removed in v3 to avoid being able to execute anything with any argument you want as it’s a risk to allow it, but it will automatically run py files through python.

In v3 the path to the py file is sufficient and will run it the same way running it from the command line will, perhaps that’s the difference in behaviour and why python can’t load the requests module.

If I open up a Terminal window, enter “/usr/bin/env python” to start python, and then enter “import requests”, it works. But the same commands at the start of the script fails. It doesn’t make sense. Based on how you said v3 works, then the script should run fine.

I’m baffled.

Does v3 ignore the python in $PATH and instead uses the system python at /usr/bin/python?

It doesn’t use anything explicitly, it just executes the python file, I’d expect the version it executes to match which python though.

That’s what I figured. Thanks.

Okay, I solved it. Even though “which python” returns the correct python and version, I had to change the python path in the script from “/usr/bin/env python” to “/usr/local/bin/python2.7”. I suspect this is an issue with how Homebrew installs python2.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.