I am trying to generate a custom QR code using the qrcode
package, but I've run into an issue where it seems that it fails on valid input. I'm wondering if this is a bug in the package or expected behavior of a QR code that I'm not familiar with.
According to this site a version 1 QR code with Medium error correction can hold up to 20 alphanumeric values. Below myStr
is a simple alphanumeric string that is 19 characters long and it fails with the output
qrcode.exceptions.DataOverflowError: Code length overflow. Data size (131) > size available (128)
However if I change myStr
from 0000000000A0000A000
to 000000000000000A000
, the string is still alphanumeric and still the same length, but then it passes.
import qrcode
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_M,
)
myStr = '0000000000A0000A000'
print(len(myStr))
qr.add_data(myStr)
qr.make(fit=False)
img = qr.make_image()
Windows, Python 2.7, qrcode version 5.3, Pillow