Kodi Community Forum

Full Version: Error running a python script in Kodi - Do I have a permission problem?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm probably trying to do something that is beyond my capability but I thought I'd try.  I'm running Kodi 18 on a Shield TV.  I'm trying to use The Scheduler addon to run the zap2epg addon python script on a schedule.  It runs fine if I manually run it in Kodi.  I get an error that the zap2epg.log file is read-only when I try to run The Scheduler.  The file is not read-only.  I've pasted the section of the kodi log that contains the error in the link below.  I can post a whole Kodi log if it will help.  
Any help would be appreciated.  
Thanks
https://paste.ubuntu.com/p/tPx2gY3MRq/
'/zap2epg.log' means it's at the root of the filesystem.
pretty sure that is read-only.
It is in the Android/data/org.xbmc.kodi/files/.kodi/userdata/addon_data/script.module.zap2epg folder.  I can make changes to it using both Windows Explorer and X-plore.  
It seems like that means it is not read-only.  Am I missing something?  
I did notice that it is in the userdata folder vs the addons folder for the zap2epg.py file.  
Thanks
as far as i can tell from your log, the addon is trying to log data to /zap2epg.log, but it does not have permissions to write in that location.
it should log to /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/userdata/addon_data/script.module.zap2epg/zap2epg.log instead.

most likely a bug in the addon i guess.
It is probably because I'm trying to run it directly from the zap2epg.py script using The Scheduler instead of running it in Kodi the way it was designed.  If I run it manually in Kodi it works fine.  
Maybe I'm taking the wrong approach.  Let me ask this a different way.  
I run this by going to Add-ons, Program add-ons, zap2epg, and then selecting "Run zap2epg and Update Guide Data" (the first item below the up one folder).  
Is there an easy way to automate this process to run at 5am every day?  
Thanks for your help!
As far as I know you can't run the script from an external source.  Even if you try to run it from adb you get:
Code:
foster:/sdcard/Android/data/org.xbmc.kodi/files/.kodi/addons/script.module.zap2epg $ python zap2epg.py
Traceback (most recent call last):
  File "zap2epg.py", line 17, in <module>
    import urllib2
ImportError: No module named urllib2
1|foster:/sdcard/Android/data/org.xbmc.kodi/files/.kodi/addons/script.module.zap2epg $ python default.py
Traceback (most recent call last):
  File "default.py", line 16, in <module>
    import xbmc,xbmcaddon,xbmcvfs,xbmcgui,xbmcplugin
ImportError: No module named xbmc

You might be able to do it with root, but I'm not sure.
Running scripts in Kodi from The Scheduler seems to work for other people but maybe they're not running Android.  
I guess I need to come up with another plan...
Thanks
I thought I'd poke at this a little further.  

I know manually running zap2epg works OK.  So if I can replicate what I do manually using Kodi built-in functions it should work.  

If I use the RunAddon function it opens zap2epg and gets me to the menu that has the option "Run zap2epg and Update Guide Data".  But it appears the RunAddon function does not allow the use of arguments.  However, the RunScript function does allow the use of arguments and can also invoke an addon by it's ID.  

But now I need to know the correct argument for "Run zap2epg and Update Guide Data".  The default.py file has:
 'label': 'Run zap2epg and Update Guide Data',
 'path': plugin.url_for(u'run'),
 'thumbnail':get_icon_path('run'),

I've tried RunScript(script.module.zap2epg, run) but it gives:
 Error Type: <type 'exceptions.IndexError'>
 Error Contents: list index out of range

Do I have the right argument?  
If not, how do I find out the correct argument?  

Thanks
Well, proving the adages a little knowledge can be dangerous, to a hammer everything looks like a nail, even a blind squirrel finds an acorn every once in a while, etc, I think I've come up with a crude, inelegant, temporary solution that is within my skill level (and it only took me a few hours).  

I installed the Kodi Cron addon (it can schedule in small increments) and I made 4 schedule jobs:
RunAddon(script.module.zap2epg)
Action(PageUp)
Action(Down)
Action(Select)

They are scheduled to run a minute apart.  They worked in a trial run.  I'll see if they work tomorrow morning starting at 5 am after the Shield has gone to sleep.  

If anyone has a more elegant solution I'm all ears.  One concern I have is things getting out of wack and selecting something dangerous.  

Thanks
Well, this seems to be working but I'm open to a less crude method.