mnooner256 / pyqrcode

Python 3 module to generate QR Codes
BSD 3-Clause "New" or "Revised" License
408 stars 74 forks source link

automatic version is too small #38

Closed goretkin closed 8 years ago

goretkin commented 8 years ago

If I understand correctly, create should find the smallest QR code that can contain the data.

import pyqrcode
pyqrcode.create("6010102401", error="H")

produces

ValueError: The supplied data will not fit within this version of a QR code.

This works great:

pyqrcode.create("6010102401", error="H", version=2)
mnooner256 commented 8 years ago

Your right, it should have autodetected. I will investigate and get back to you.

mnooner256 commented 8 years ago

Thanks for the report

I believe I fixed the issue.

When I added support for unicode and kanji, the numeric encoding function developed a problem. Since the QR code is encoded using bytes now, the iterator was converting it to an integer, i.e. the character's ordinal value, behind the scenes. Literally, bytes went in and integers came out. When I was using string types this did not happen. The fix was simple, if the digit is an integer (i.e. the digit character's ordinal), convert it back to a character.

I wrote some tests to confirm that version 1 is contents and size detection is working appropriately. They can be found in tests/test_issue38.py file. The first test case is the error you reported.

Would you pull from the main repo and check that it now functions for your purposes?

Once again, thanks for the bug report.

goretkin commented 8 years ago

Ahh, so the original code does fit in a version-1 code? That makes sense.

The numeric codes are also now working! I thought perhaps there was an issue with my QR reader.

Thank you so much for the speedy response.

mnooner256 commented 8 years ago

Great. I will push the update to pypi tonight.

Thanks for the report.