doccaz / scc-tools

A set of simple tools to interact with SUSE Customer Center (SCC)
MIT License
12 stars 1 forks source link

Python 3.4 needs explicit json encoding #14

Closed frispete closed 3 years ago

frispete commented 3 years ago

Hi,

according to https://docs.python.org/3/library/json.html#json.loads needs explicit encoding on older Python 3: Changed in version 3.6: s can now be of type bytes or bytearray. The input encoding should be UTF-8, UTF-16 or UTF-32.

We applied this to get it working internally:

--- vercheck.py.old     2021-08-30 13:55:05.124482403 +0200
+++ vercheck.py 2021-08-30 13:15:28.445376243 +0200
@@ -478,11 +478,11 @@
                        if r.status == 200:
                                if tries > 0:
                                        print('thread %d got a good reply after %d tries' % (self.instance_nr, tries))
-                               return_data = json.loads(r.data)
+                               return_data = json.loads(r.data.decode('utf-8'))
                                valid_response = True
                        elif r.status in self.error_states:
                                if r.data:
-                                       json_data = json.loads(r.data)
+                                       json_data = json.loads(r.data.decode('utf-8'))
                                        print('cannot be processed due to error: [' + json_data['error'] + ']')
                                print('thread %d got a fatal error (%d). Results will be incomplete!\nPlease contact the service administrators or try again later.' % (self.instance_nr, r.status))
                                break
doccaz commented 3 years ago

Thank you! FIxed.