From 6348dc01a45af6ed63c09326ec94cd425db1d6d7 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 4 Jan 2024 16:18:00 -0500 Subject: [PATCH] hardwareprofile: remove external dependency on simplejson This uses the requests module and converts requests responses to json using requests' own `.json()` method on responses. For incomprehensible reasons, requests has spent about a decade using either simplejson or the standard library's json module more or less at will, and returning either one or the other exception types. They don't know why they use simplejson, we don't know why they use simplejson. In requests 3 (which will be released in the Year Of The Linux Desktop or when pigs fly, whichever one comes later) simplejson is dropped entirely. There are innumerable issues discussing the problem on the requests bugtracker, with the general consensus being that it's better to randomly return either one of two different libraries and two different library return types in errors -- because it was historically done that way and people might be depending on it. ?????? Bugs: https://github.com/psf/requests/pull/710 https://github.com/psf/requests/pull/2516 https://github.com/psf/requests/issues/3052 https://github.com/psf/requests/issues/4169 https://github.com/psf/requests/issues/4842 https://github.com/psf/requests/issues/5794 https://github.com/psf/requests/issues/6084 The awkward workaround is to guarantee that requests' silent behavior of using simplejson *if it is installed* is forcibly triggered by forcibly depending on simplejson, and then catching the simplejson exception. The better solution here is pretty simple: do not rely on the requests module's automatic json conversion, this is as simple as using the already-imported json module and calling json.loads() on the retrieved content. Fixes: 1df343e9ab7defa284a73390210a65cf2112f17e Reimplements: bb154a843b737cc3ad8c1a45fa04a1a3609aff05 --- .github/workflows/buildmaster.yml | 2 +- mythtv/configure | 3 +-- mythtv/programs/scripts/hardwareprofile/smolt.py | 5 ++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/buildmaster.yml b/.github/workflows/buildmaster.yml index 6894984bbc9..10af0e1d930 100644 --- a/.github/workflows/buildmaster.yml +++ b/.github/workflows/buildmaster.yml @@ -48,7 +48,7 @@ jobs: sudo apt install ccache qt5-qmake qtscript5-dev nasm libsystemd-dev libfreetype6-dev libmp3lame-dev libx264-dev libx265-dev libxrandr-dev libxml2-dev sudo apt install libavahi-compat-libdnssd-dev libasound2-dev liblzo2-dev libhdhomerun-dev libsamplerate0-dev libva-dev libdrm-dev libvdpau-dev sudo apt install libass-dev libpulse-dev libcec-dev libssl-dev libtag1-dev libbluray-dev libbluray-bdj libgnutls28-dev libqt5webkit5-dev - sudo apt install libvpx-dev python3-mysqldb python3-lxml python3-simplejson python3-future python3-setuptools libdbi-perl libdbd-mysql-perl libnet-upnp-perl + sudo apt install libvpx-dev python3-mysqldb python3-lxml python3-future python3-setuptools libdbi-perl libdbd-mysql-perl libnet-upnp-perl sudo apt install libio-socket-inet6-perl libxml-simple-perl libqt5sql5-mysql libwayland-dev qtbase5-private-dev libzip-dev libsoundtouch-dev if: runner.os == 'Linux' diff --git a/mythtv/configure b/mythtv/configure index 7fb9ff640e2..7db121f3973 100755 --- a/mythtv/configure +++ b/mythtv/configure @@ -5535,7 +5535,7 @@ if enabled bdjava; then java_code_version=1.4 javac_version=`"${JAVAC}" -version 2>&1 | head -n 1` - + echo "${javac_version}" | grep -E -q '^javac (9|1[0-1])' && java_code_version=1.6 echo "${javac_version}" | grep -E -q '^javac (1[2-9])' && java_code_version=1.7 echo "${javac_version}" | grep -E -q '^javac (2.*)' && java_code_version=1.7 @@ -6563,7 +6563,6 @@ if enabled bindings_python; then check_py_lib MySQLdb || disable_bindings_python "MySQLdb" check_py_lib lxml || disable_bindings_python "lxml" check_py_lib requests || disable_bindings_python "requests" - check_py_lib simplejson || disable_bindings_python "simplejson" check_py_lib future || disable_bindings_python "future" check_python "(3,11,1)" && check_py_lib wheel && check_py_lib_version pip "(23,0,1)" && USE_PYTHON_PIP="yes" fi diff --git a/mythtv/programs/scripts/hardwareprofile/smolt.py b/mythtv/programs/scripts/hardwareprofile/smolt.py index 1bcc8060d07..464f068d6fc 100644 --- a/mythtv/programs/scripts/hardwareprofile/smolt.py +++ b/mythtv/programs/scripts/hardwareprofile/smolt.py @@ -50,7 +50,6 @@ from urlparse import urlparse import json from json import JSONEncoder -from simplejson import errors as sje import datetime import logging @@ -790,8 +789,8 @@ def serialize(object, human=False): sys.exit(1) try: - admin_obj = admin_token.json() - except sje.JSONDecodeError: + admin_obj = json.loads(admin_token.content) + except json.JSONDecodeError: self.session.close() error(_('Incorrect server response. Expected a JSON string')) return (1, None, None)