Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QRCodeEncoder fails #8

Open
karolyi opened this issue Aug 5, 2017 · 9 comments
Open

QRCodeEncoder fails #8

karolyi opened this issue Aug 5, 2017 · 9 comments

Comments

@karolyi
Copy link

karolyi commented Aug 5, 2017

Hey,

I'm trying to convert the string 'B-4-1-20170805-6' into a QR-Code, but pyStrich raises an error:

Python 3.6.1 (default, Mar 22 2017, 06:17:05)
[GCC 6.3.0 20170321] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pystrich.qrcode import QRCodeEncoder
>>> encoder = QRCodeEncoder('B-4-1-20170805-6')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/project/venv/lib/python3.6/site-packages/pystrich/qrcode/__init__.py", line 30, in __init__
    self.matrix = enc.encode(text, ecl)
  File "/project/venv/lib/python3.6/site-packages/pystrich/qrcode/textencoder.py", line 78, in encode
    self.create_matrix()
  File "/project/venv/lib/python3.6/site-packages/pystrich/qrcode/textencoder.py", line 197, in create_matrix
    matrix_content = self.minfo.create_matrix(self.version, self.codewords)
  File "/project/venv/lib/python3.6/site-packages/pystrich/qrcode/isodata.py", line 100, in create_matrix
    codeword_i = codewords[i]
IndexError: list index out of range

please investigate.

cheers

@edkirin
Copy link

edkirin commented Sep 19, 2017

Another bug report for this issue:

`
In [13]: from pystrich.qrcode import QRCodeEncoder

In [14]: encoder = QRCodeEncoder('00231872347699829949')

IndexError Traceback (most recent call last)
in ()
----> 1 encoder = QRCodeEncoder('00231872347699829949')

/home/eden/env/pdfworker2/lib/python3.5/site-packages/pystrich/qrcode/init.py in init(self, text, ecl)
28
29 enc = TextEncoder()
---> 30 self.matrix = enc.encode(text, ecl)
31 self.height = 0
32 self.width = 0

/home/eden/env/pdfworker2/lib/python3.5/site-packages/pystrich/qrcode/textencoder.py in encode(self, text, ecl)
76 "Codewords: " + ' '.join([str(codeword) for codeword in self.codewords]))
77
---> 78 self.create_matrix()
79
80 return self.matrix

/home/eden/env/pdfworker2/lib/python3.5/site-packages/pystrich/qrcode/textencoder.py in create_matrix(self)
195 """Create QR Code matrix"""
196
--> 197 matrix_content = self.minfo.create_matrix(self.version, self.codewords)
198 self.mtx_size = len(matrix_content)
199

/home/eden/env/pdfworker2/lib/python3.5/site-packages/pystrich/qrcode/isodata.py in create_matrix(self, version, codewords)
95 i = 0
96 while i < max_codewords:
---> 97 codeword_i = codewords[i]
98 j = 7
99 while j >= 0:

IndexError: list index out of range

`

@MrSurly
Copy link

MrSurly commented Feb 8, 2018

Also having this problem.

@karolyi
Copy link
Author

karolyi commented Feb 8, 2018

@MrSurly @edkirin and anyone else who has this problem, consider changing to https://github.com/lincolnloop/python-qrcode

@edkirin
Copy link

edkirin commented Feb 8, 2018

@karolyi Thanks for info, I will check this lib.

@MrSurly
Copy link

MrSurly commented Feb 8, 2018

@karolyi I was looking for a generic library that does DMTX and QR, since my present QR generator makes rather large codes that don't print very clearly on my tiny labels.

@karolyi
Copy link
Author

karolyi commented Feb 8, 2018

@MrSurly I feel you. I also wanted to use a more generic purpose data code imager library like this, but since this doesn't work and seemingly has no support, I was forced to change to the other one.

@MrSurly
Copy link

MrSurly commented Feb 8, 2018

@karolyi I'm probably also going to change over -- has more control over the final size of the QR code, which is what I'm looking for, though I would like an API for accessing the individual pixels.

@mmulqueen
Copy link
Owner

mmulqueen commented Feb 9, 2018

I've had a look at this today. Ultimately, the code of this project is a mess and the tests are too high level to really help narrow down what's going on. This library is a Python 3 port of huBarcode (itself seemingly abandoned), with various improvements, but certainly not a re-write. If you run git blame on the responsible lines of code, you'll see that most of them are over a decade old.

I regularly use the code39, code128 and datamatrix aspects of this library, so I know those are relatively battle tested. I don't use the ean or qrcode parts. I've got some knowledge about how code39, code128 and datamatrix work and I've read a good chunk of the standardisation documentation about them. I know almost nothing about qrcode.

It looks to me like this bug only affects certain strings. It disappears by changing the case of the letter B in B-4-1-20170805-6 or changing one of the digits in 00231872347699829948. Digging deeper, it appears that error originates from the error correction codewords being 1 word too short. Everything else like the padding looks fine to me (again, I'm no expert).

So you're more than welcome to find the root cause and submit a patch. My recommendation would be to use a library that's better maintained for QR. The linked python-qrcode looks a lot cleaner to me in terms of implementation (no reliance on mysterious .dat files) - I can actually understand what's going on. I'd ideally drop QR support from this library, but I know people are using it.

This project is unlikely to receive major updates. I'd favour a re-write over trying to improve most of the existing code - this is something else that I don't currently have time for.

EDIT: Forgot to add. This bug is also present in huBarcode, so is unrelated to the port to Python 3. I haven't found a bug report for it though.

mmulqueen added a commit that referenced this issue Feb 9, 2018
pidupuis added a commit to pidupuis/pyStrich that referenced this issue Mar 13, 2018
@darkfader
Copy link

My workaround was just to iterate through the various levels of redundancy until it passes. I only used used it for small numbers though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants