PyQRCode, how to decode raw bytes?

1.3k views Asked by At

with PyQRCode I want to generate QR Code for the following image

R606101.png

Zxing Decoder Online reports:

Raw text:  �R606101.
Raw bytes: 40 98 05 23 63 03 63 13   03 12 e0 ec 11 ec 11 ec

and here my python script

import pyqrcode 
import png 
from pyqrcode import QRCode
import re 

# Raw bytes which represents the QR code 
s = "40 98 05 23 63 03 63 13   03 12 e0 ec 11 ec 11 ec"
s = re.sub(r"((?![a-f0-9]).)", "", s)
print(s)

t = bytes.fromhex(s).decode('latin-1')
print(t) # error: it print @˜♣#c♥c‼♥↕àì◄ì◄ì not �R606101.
  
# Generate QR code 
url = pyqrcode.create(t, encoding='latin-1') 
  
# Create and save the png file naming "myqr.png" 
url.png('myqr.png', quiet_zone=1, scale = 20) 

But the code above produce strange characters and different QR Code image

1

There are 1 answers

0
Ali Amigh On

you can use decode('latin-1') and encode('latin-1') before and after create qr code from raw bytes this make byte to characters that identified by pyqrcode