【问题标题】:PyQRCode, how to decode raw bytes?PyQRCode,如何解码原始字节?
【发布时间】:2020-08-28 17:27:38
【问题描述】:

使用 PyQRCode 我想为下面的图片生成二维码

Zxing解码器在线报道:

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

这里是我的 python 脚本

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) 

但上面的代码会产生奇怪的字符和不同的二维码图像

【问题讨论】:

    标签: python python-3.x qr-code


    【解决方案1】:

    您可以在从原始字节创建二维码之前和之后使用 decode('latin-1') 和 encode('latin-1') 这会将字节转换为 pyqrcode 识别的字符

    【讨论】:

      猜你喜欢
      • 2019-03-24
      • 1970-01-01
      • 2010-11-24
      • 2019-12-29
      • 2013-12-03
      • 2014-12-17
      • 1970-01-01
      • 2021-08-12
      • 1970-01-01
      相关资源
      最近更新 更多