Confusing problem when trying to read a json file
#1
[SOLVED:] using br instead of r fixed it
Code:
with open(config_file, mode='rb') as f:

Trying to translate my Matrix plugin to leia but currently stuck at this problem...
Executing the following piece of code works the first time but after that it fails constantly until KODI is rebooted.

python:
#This should be working but it isn't!
if os.path.isfile(config_file):
    with open(config_file, 'r') as f:
        CONFIG = json.load(f)
Code:
with open(config_file, 'r') as f:
TypeError: attribute of type 'NoneType' is not callable
-->End of Python script error report<--
Build: 18.7 2020-05-20
Reply
#2
(2020-05-28, 20:22)evantaur Wrote: Trying to translate my Matrix plugin to leia but currently stuck at this problem...
Executing the following piece of code works the first time but after that it fails constantly until KODI is rebooted.

python:
#This should be working but it isn't!
if os.path.isfile(config_file):
    with open(config_file, 'r') as f:
        CONFIG = json.load(f)
Code:
with open(config_file, 'r') as f:
TypeError: attribute of type 'NoneType' is not callable
-->End of Python script error report<--
Build: 18.7 2020-05-20

Kodi 18 uses a Python 2.7 environment (just in case you didn't know).  It's possible that won't work in 2.7.  You also might want to consider using xbmcvfs instead of regular python calls for opening files.  It gives you better compatibility across platforms and network mounts.  And I know for a fact that the with as statement WILL NOT work with the Leia version of xbmcvfs, and that's why I'm wondering if it isn't an option for "regular" Python as well.

https://codedocs.xyz/xbmc/xbmc/group__py...mcvfs.html
Reply
#3
Quote:Kodi 18 uses a Python 2.7 environment (just in case you didn't know). 
for some reason i was thinking it was using some ancient 2.0 :'D (yeah i'm literally crying at the moment, you saved my weekend)
Quote:You also might want to consider using xbmcvfs instead of regular python calls for opening files.
Yeah in the process of doing just that, those calls are remnants from the proof of concept times when my addon was just a standalone python file, but the real problem was that i had to open the file in binary mode...no idea why but it works now.

Thanks once again for saving countless hours of my time.
Reply

Logout Mark Read Team Forum Stats Members Help
Confusing problem when trying to read a json file0