Kodi Community Forum
Android Kodi ssh python script *no such file or directory* - Printable Version

Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
--- Thread: Android Kodi ssh python script *no such file or directory* (/showthread.php?tid=338442)



Kodi ssh python script *no such file or directory* - bkafi - 2018-12-17

Im trying to run a python script through kodi submenu button which opens a SSH connection to my remote Raspberry Pi and runs a .sh script. However it sems like Kodi cant resolve paths very well.
I have ran this same python script from termux and it runs fine.

Not sure if i have to use xbmc.translatepath. Any kodi legends out there know what im doing wrong?

If theres a better way of doing this im all ears Smile

XBMC.RunScript(special://home\addons\script.hyperion\hyperion_on.py)
Code:
#!/usr/bin/python2
import subprocess
subprocess.call('ssh [email protected] -p 22 -i /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.hyperion/.ssh/id_rsa bash "/home/pi/hyperion_on.sh"', shell=True)

Remote script on Pi hyperion_on.sh
Code:

echo  '{ "command": "clearall"}' | nc 192.168.1.14 19444

Error:
Code:

ERROR: EXCEPTION Thrown (PythonToCppException) :
-->Python callback/script returned the following error<--- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.OSError'>
Error Contents: [Errno 2] No such file or directory
Traceback (most recent call last):
File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.hyperion/hyperion_on.py", line 17, in <module> subprocess.call('ssh [email protected] -p 22 -i /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.hyperion/.ssh/id_rsa bash "/home/pi/hyperion_on.sh"', shell=True)
File "/home/jenkins/workspace/Android-ARM/tools/depends/xbmc-depends/arm-linux- androideabi-android-21/lib/python2.7/subprocess.py", line 523, in call
File "/home/jenkins/workspace/Android-ARM/tools/depends/xbmc-depends/arm-linux- androideabi-android-21/lib/python2.7/subprocess.py", line 711, in __init__ File "/home/jenkins/workspace/Android-ARM/tools/depends/xbmc-depends/arm-linux- androideabi-android-21/lib/python2.7/subprocess.py", line 1343, in _execute_child
OSError: [Errno 2] No such file or directory -->End of Python script error report<--



RE: Kodi ssh python script *no such file or directory* - V8MEM - 2018-12-17

running external binaries in android kodi is always going to be a headache, You are better off setting up an http API for whatever you are trying to do.


RE: Kodi ssh python script *no such file or directory* - bkafi - 2018-12-18

I just came across this script and it works from Kodi in windows.

Windows Kodi 
XBMC.RunScript(special://home\addons\script.hyperion\hyperion_on.py)
Code:
#!/usr/bin/python

from __future__ import print_function
import os
import subprocess
import platform
import xbmc
import xbmcgui

PRIVATE_KEY_LOCATION = "C:/Users/Damien/AppData/Roaming/Kodi/addons/script.hyperion/.ssh/id_rsa"
USER = "pi"
HOST = "192.168.1.14"
COMMAND="bash /home/pi/hyperion_off.sh"
# Ports are handled in ~/.ssh/config since we use OpenSSH

system32 = os.path.join(os.environ['SystemRoot'], 'SysNative' if platform.architecture()[0] == '32bit' else 'System32')
ssh_path = os.path.join(system32, 'OpenSSH/ssh.exe')

ssh = subprocess.Popen([ssh_path, '-i', PRIVATE_KEY_LOCATION, "{}@{}".format(USER, HOST)],
                       stdin=subprocess.PIPE,
                       stdout=subprocess.PIPE,
                       stderr=subprocess.PIPE)

std_data = ssh.communicate(COMMAND)

dialog = xbmcgui.Dialog()
dialog.notification('HYPERION', 'HYPERION has been turned OFF', 'C:/Users/Damien/AppData/Roaming/Kodi/addons/script.hyperion/icon.png', 5000, True)

Made some changes to it for Android, fingers crossed. Will test tonight.
Android Kodi 
XBMC.RunScript(special://home\addons\script.hyperion\hyperion_on.py)
Code:
#!/usr/bin/python

from __future__ import print_function
import os
import subprocess
import platform
import xbmc
import xbmcgui

PRIVATE_KEY_LOCATION = "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.hyperion/.ssh/id_rsa"
USER = "pi"
HOST = "192.168.1.14"
COMMAND="bash /home/pi/hyperion_off.sh"
# Ports are handled in ~/.ssh/config since we use OpenSSH

#system32 = os.path.join(os.environ['SystemRoot'], 'SysNative' if platform.architecture()[0] == '32bit' else 'System32')
ssh_path = os.path.join('/data/data/com.termux/files/usr/bin/ssh')

ssh = subprocess.Popen([ssh_path, '-i', PRIVATE_KEY_LOCATION, "{}@{}".format(USER, HOST)],
                       stdin=subprocess.PIPE,
                       stdout=subprocess.PIPE,
                       stderr=subprocess.PIPE)

std_data = ssh.communicate(COMMAND)

dialog = xbmcgui.Dialog()
dialog.notification('HYPERION', 'HYPERION has been turned OFF', '/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.hyperion/icon.png', 5000, True)



RE: Kodi ssh python script *no such file or directory* - bkafi - 2018-12-18

Ok so that didn't work. From what i believe it to be is permission based.

Code:
ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.OSError'>
Error Contents: [Errno 13] Permission denied
Traceback (most recent call last):
File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.hyperion/hyperion_on.py", line 22, in <module>
stderr=subprocess.PIPE)
File "/home/jenkins/workspace/Android-ARM/tools/depends/xbmc-depends/arm-linux-androideabi-android-21/lib/python2.7/subprocess.py", line 711, in __init__
File "/home/jenkins/workspace/Android-ARM/tools/depends/xbmc-depends/arm-linux-androideabi-android-21/lib/python2.7/subprocess.py", line 1343, in _execute_child
OSError: [Errno 13] Permission denied
-->End of Python script error report<--

Due to Android locking down the sdcard = /storage/emulated/0/... i cant set the python file to be executable.
Anyone know away around this? I thought i read somewhere that if you create an actual addon you can tell it its executable??

Ideally I want to avoid rooting the Xiamoi Mi Box if I dont have to.


RE: Kodi ssh python script *no such file or directory* - bkafi - 2018-12-19

I'm starting to think this isn't possible even with rooting the device as /storage/emulated/0/ will still be locked down as its emulated storage and i wont be able to set the script as executable.

Could I store the python file in /data/data/com.termux/files/home/scripts folder as i can set it to be executable and tell kodi in the custom action button that its located in XBMC.RunScript(/data/data/com.termux/files/home/scripts/hyperion_on.py) ? Will this work?

Does anyone have any ideas on a better method? Can i use hyperion's json interface to remotely control Hyperion?

My current setup is

Hardware:
Xiaomi Mi Box 3 Global Version running Kodi 17.6 Krypton.
Raspberry Pi 3 B+ running Raspbian 9 Stretch and hyperion with Fushicai USBTV007 Video Grabber.

Issue:
Stupid RCA / Composite / AV (Input) to HDMI Video (Output) Converter Adapter outputs the rainbow image when no signal is detected, so im looking to turn off the lights from a button in kodi to my remote raspberry pi.


RE: Kodi ssh python script *no such file or directory* - bhagat101 - 2018-12-24

(2018-12-17, 00:42)bkafi Wrote: Im trying to run a python script through kodi submenu button which opens a SSH connection to my remote Raspberry Pi and runs a .sh script. However it sems like Kodi cant resolve paths very well.
I have ran this same python script from termux and it runs fine.

Not sure if i have to use xbmc.translatepath. Any kodi legends out there know what im doing wrong?

If theres a better way of doing this im all ears Smile

XBMC.RunScript(special://home\addons\script.hyperion\hyperion_on.py)
Code:
#!/usr/bin/python2
import subprocess
subprocess.call('ssh [email protected] -p 22 -i /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.hyperion/.ssh/id_rsa bash "/home/pi/hyperion_on.sh"', shell=True)

Remote script on Pi hyperion_on.sh
Code:

echo  '{ "command": "clearall"}' | nc 192.168.1.14 19444

Error:
Code:

ERROR: EXCEPTION Thrown (PythonToCppException) :
-->Python callback/script returned the following error<--- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.OSError'>
Error Contents: [Errno 2] No such file or directory
Traceback (most recent call last):
File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.hyperion/hyperion_on.py", line 17, in <module> subprocess.call('ssh [email protected] -p 22 -i /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.hyperion/.ssh/id_rsa bash "/home/pi/hyperion_on.sh"', shell=True)
File "/home/jenkins/workspace/Android-ARM/tools/depends/xbmc-depends/arm-linux- androideabi-android-21/lib/python2.7/subprocess.py", line 523, in call
File "/home/jenkins/workspace/Android-ARM/tools/depends/xbmc-depends/arm-linux- androideabi-android-21/lib/python2.7/subprocess.py", line 711, in __init__ File "/home/jenkins/workspace/Android-ARM/tools/depends/xbmc-depends/arm-linux- androideabi-android-21/lib/python2.7/subprocess.py", line 1343, in _execute_child
OSError: [Errno 2] No such file or directory -->End of Python script error report<--
 Its not a bigger problem you are facing. There are no. of the solution and you get it easily on Google.


RE: Kodi ssh python script *no such file or directory* - moejoe - 2020-06-18

(2018-12-24, 10:37)bhagat101 Wrote:
(2018-12-17, 00:42)bkafi Wrote: Im trying to run a python script through kodi submenu button which opens a SSH connection to my remote Raspberry Pi and runs a .sh script. However it sems like Kodi cant resolve paths very well.
I have ran this same python script from termux and it runs fine.

Not sure if i have to use xbmc.translatepath. Any kodi legends out there know what im doing wrong?

If theres a better way of doing this im all ears Smile

XBMC.RunScript(special://home\addons\script.hyperion\hyperion_on.py)
Code:
#!/usr/bin/python2
import subprocess
subprocess.call('ssh [email protected] -p 22 -i /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.hyperion/.ssh/id_rsa bash "/home/pi/hyperion_on.sh"', shell=True)

Remote script on Pi hyperion_on.sh
Code:

echo  '{ "command": "clearall"}' | nc 192.168.1.14 19444

Error:
Code:

ERROR: EXCEPTION Thrown (PythonToCppException) :
-->Python callback/script returned the following error<--- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.OSError'>
Error Contents: [Errno 2] No such file or directory
Traceback (most recent call last):
File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.hyperion/hyperion_on.py", line 17, in <module> subprocess.call('ssh [email protected] -p 22 -i /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.hyperion/.ssh/id_rsa bash "/home/pi/hyperion_on.sh"', shell=True)
File "/home/jenkins/workspace/Android-ARM/tools/depends/xbmc-depends/arm-linux- androideabi-android-21/lib/python2.7/subprocess.py", line 523, in call
File "/home/jenkins/workspace/Android-ARM/tools/depends/xbmc-depends/arm-linux- androideabi-android-21/lib/python2.7/subprocess.py", line 711, in __init__ File "/home/jenkins/workspace/Android-ARM/tools/depends/xbmc-depends/arm-linux- androideabi-android-21/lib/python2.7/subprocess.py", line 1343, in _execute_child
OSError: [Errno 2] No such file or directory -->End of Python script error report<--
 Its not a bigger problem you are facing. There are no. of the solution and you get it easily on Google.

I wanna do that via CoreELEC(LibreELEC). Was anyone successful in executing a script to shut down a NAS via SSH?


This forum uses Lukasz Tkacz MyBB addons.