Browse Source

fix qr error generation error

Pi 3 weeks ago
parent
commit
64802d0721
1 changed files with 5 additions and 4 deletions
  1. 5 4
      rest/qr.py

+ 5 - 4
rest/qr.py

@@ -11,12 +11,13 @@ QR_MAX_BYTES = {
     ERROR_CORRECT_L: 2953,
 }
 QR_QUALITY_MAP = {
-  q: locals().get(f'ERROR_CORRECT_{q}') for q in (
-    'H', 'Q', 'M', 'L'
-  )
+  'H': ERROR_CORRECT_H,
+  'Q': ERROR_CORRECT_Q,
+  'M': ERROR_CORRECT_M,
+  'L': ERROR_CORRECT_L,
 }
 def get_qr_code(data: Union[bytes, str], fallback: Union[bytes, str] = None, err_lvl='H'):
-    err_lvl = QR_QUALITY_MAP.get(err_lvl, err_lvl)
+    err_lvl = QR_QUALITY_MAP.get(err_lvl, ERROR_CORRECT_H)
     qr = QRCode(error_correction=err_lvl)
     if data is not None and isinstance(data, str):
         data = data.encode('utf-8')