I am trying to modify an existing addon to add the possibility to have user configuration from within anki and not have to make changes to the source files of the addon. So I did this by creating a new file config.json and config.md in the addon folder, and inside the code file i added this line of command
config = mw.addonManager.getConfig(__name__)
and then when I try
default_hour_count = config["default_hour_count"] or
default_hour_count = config.get("default_hour_count")
(with default_hour_count being the name of a parmeter I included in the json file)
An error occurs that says that config is of None type, so obviously the getConfig didn’t work, but I don’t understand why. I saw somewhere else that the encoding of the json file could be a problem but I checked and it is UTF-8 which should be correct.
Thanks to anyone who will stop by to bring some light into this !
1 Like
Could you send your config.json
? I suspect it may be malformed. A common trap with .json
files is to not put quotes around the keys.
Here’s a very basic config loader:
1 Like
In my case the Config None error often occurs when I forget to create config.json
.
config.json
must be in the same directory as __init__.py
. e.g. it will not work if you put it in a folder like user_files
.
To get the key by config[“default_hour_count”]
, you need to set the default value.
config.json
{
"default_hour_count": true
}
You can omit the default config if you get the value like config.get(“default_hour_count”, True)
. But at least a file like this is required.
config.json
{}
If using older Anki occasionally an error may occur that mw is None, but this error doesn’t seem to occur with recent Anki.
1 Like
I could not send the json file as is, but I copied part of its content below (the rest is really written the same, no missing comma, and I tried making it work with this minimal version anyway but it still doesn’t)
{
"default_hour_count": 1,
"default_min_count": 30,
"default_sec_count": 0
}
And the config.json is located in the same directory as the __init__.py
file
1 Like
The code looks fine so that problem is odd. If you share the entire code on Github it might help.