Browse Source

syntax labkeyDatabaseBrowser error

Andrej 7 months ago
parent
commit
7de6317df7
1 changed files with 3 additions and 2 deletions
  1. 3 2
      labkeyDatabaseBrowser.py

+ 3 - 2
labkeyDatabaseBrowser.py

@@ -78,12 +78,13 @@ class labkeyDB:
       return self.toJSON(response)
 
    def toJSON(self,response):
-      encoding=chardet.detect(response.data)["encoding"]
+      data=response.data
+      encoding=chardet.detect(data)["encoding"]
       #try with a set of encodings to maximize probability of success
       encodings=[encoding,'utf_8']
       for x in encodings:
          try:
-            return json.loads(response.data.decode(x))
+            return json.loads(data.decode(x))
          except UnicodeDecodeError:
             print(f'Failed to decode with [{x}]: {data}')
       return None