open file using 'special protocol'
#1
Hello,

I want the plugin to open a file during the running of the addon so it can read/write information from/to it.

I keep getting the Error - 'Permission Denied'.

This is the code:

Code:
ACCOUNT_FILE_PATH = "special://xbmc//addons//plugin.video.movieTalk//account.txt"

account_file = open(ACCOUNT_FILE_PATH, "w")


Is it something with my syntax?
Reply
#2
(2017-06-02, 15:59)yarin.levy2 Wrote: Hello,

I want the plugin to open a file during the running of the addon so it can read/write information from/to it.

I keep getting the Error - 'Permission Denied'.

This is the code:

Code:
ACCOUNT_FILE_PATH = "special://xbmc//addons//plugin.video.movieTalk//account.txt"

account_file = open(ACCOUNT_FILE_PATH, "w")


Is it something with my syntax?

No, but you are trying to use a "special" URL in a standard Python function that does not know anything about Kodi and its special URLs. Use xbmcvfs module instead.

Code:
from contextlib import closing
from xbmcvfs import File

with closing(File(path, 'w')) as fo:
    fo.write(some_data)
Reply
#3
(2017-06-02, 16:10)Roman_V_M Wrote:
(2017-06-02, 15:59)yarin.levy2 Wrote: Hello,

I want the plugin to open a file during the running of the addon so it can read/write information from/to it.

I keep getting the Error - 'Permission Denied'.

This is the code:

Code:
ACCOUNT_FILE_PATH = "special://xbmc//addons//plugin.video.movieTalk//account.txt"

account_file = open(ACCOUNT_FILE_PATH, "w")


Is it something with my syntax?

No, but you are trying to use a "special" URL in a standard Python function that does not know anything about Kodi and its special URLs. Use xbmcvfs module instead.

Code:
from contextlib import closing
from xbmcvfs import File

with closing(File(path, 'w')) as fo:
    fo.write(some_data)


Works like magic.
Thank you very much
Reply
#4
Although I need to note that an addon data folder is a recommended place to store addon's persistent data:
Code:
from xbmcaddon import Addon

data_dir = Addon().getAddonInfo('profile').decode('utf-8')
Reply
#5
(2017-06-02, 17:05)Roman_V_M Wrote: Although I need to note that an addon data folder is a recommended place to store addon's persistent data:
Code:
from xbmcaddon import Addon

data_dir = Addon().getAddonInfo('profile').decode('utf-8')


I like the idea but it seems that it does nothing. Not opening a directory in ...AppData\Roaming\Kodi\userdata\addon_data and not opening a file.

The code is:

Code:
ACCOUNT_FILE_PATH = data_dir + "/account.txt"
(checked by xbmcgui.Dialog().ok - it is actually : "special://profile/addon_data/plugin.video.movieTalk//account.txt")

I tried:

Code:
with closing(File(ACCOUNT_FILE_PATH, 'w')) as fo:
    fo.write("username " + str(usernameID) + "\npassword " + str(password))

and also:

Code:
account_file = File(ACCOUNT_FILE_PATH, 'w')
account_file.write("username " + str(usernameID) + "\n" + "password " + str(password))
account_file.close()

What can be the cause for no such file created?


Thanks.
Reply
#6
If you did not save settings for your addon, the profile folder may not exist. In this case you need to create it.
Reply

Logout Mark Read Team Forum Stats Members Help
open file using 'special protocol'0