Encoding parameter to json.load was removed in Python 3.9

This commit is contained in:
Odd Stråbø 2020-12-21 19:27:42 +01:00
parent a51fd6b932
commit 084cf6f45d

View file

@ -3,10 +3,10 @@ from __future__ import division, absolute_import, print_function, unicode_litera
################################################################################################# #################################################################################################
import datetime import datetime
import logging
import json import json
import os import os
import sqlite3 import sqlite3
import sys
from kodi_six import xbmc, xbmcvfs from kodi_six import xbmc, xbmcvfs
from six import text_type from six import text_type
@ -317,13 +317,15 @@ def reset_artwork():
def get_sync(): def get_sync():
if (3, 0) <= sys.version_info < (3, 6):
LOG.error("Python versions 3.0-3.5 are NOT supported.")
if not xbmcvfs.exists(ADDON_DATA): if not xbmcvfs.exists(ADDON_DATA):
xbmcvfs.mkdirs(ADDON_DATA) xbmcvfs.mkdirs(ADDON_DATA)
try: try:
with open(os.path.join(ADDON_DATA, 'sync.json'), 'rb') as infile: with open(os.path.join(ADDON_DATA, 'sync.json'), 'rb') as infile:
sync = json.load(infile, encoding='utf-8') sync = json.load(infile)
except Exception: except Exception:
sync = {} sync = {}
@ -350,22 +352,16 @@ def save_sync(sync):
def get_credentials(): def get_credentials():
if (3, 0) <= sys.version_info < (3, 6):
LOG.error("Python versions 3.0-3.5 are NOT supported.")
if not xbmcvfs.exists(ADDON_DATA): if not xbmcvfs.exists(ADDON_DATA):
xbmcvfs.mkdirs(ADDON_DATA) xbmcvfs.mkdirs(ADDON_DATA)
try: try:
with open(os.path.join(ADDON_DATA, 'data.json'), 'rb') as infile: with open(os.path.join(ADDON_DATA, 'data.json'), 'rb') as infile:
credentials = json.load(infile, encoding='utf8') credentials = json.load(infile)
except Exception: except IOError:
try:
with open(os.path.join(ADDON_DATA, 'data.txt'), 'rb') as infile:
credentials = json.load(infile, encoding='utf-8')
save_credentials(credentials)
xbmcvfs.delete(os.path.join(ADDON_DATA, 'data.txt'))
except Exception:
credentials = {} credentials = {}
credentials['Servers'] = credentials.get('Servers', []) credentials['Servers'] = credentials.get('Servers', [])