mnooner256 / pyqrcode

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

Storing ANSI/ISO-8859-1 in QR Code #69

Closed chungyau97 closed 5 years ago

chungyau97 commented 5 years ago

I have a hex string hexString = "22fd30df7c13fb69f7f87e3a8728f0daf6ab360b82ec9e6d8c1157e19add4013080b3399eff31644e24553e9c30b697078492d9da33bf0a9235ab87a7662398a06c782a31acfc79c5023344b11f3750bb98e500b01" ansi = bytes.fromhex(hexString ).decode('ANSI')

version = 8 scalepermodule = 10 r_image = 'bigcoder{}_{}_m.png'.format(version, scalepermodule)

bigcode_r = pyqrcode.create(ansi , error='M', version=version,mode='binary') bigcode_r.png(r_image, scale=scalepermodule, module_color=[0, 0, 0], background = [0xff,0,0])

Keep getting error: UnicodeEncodeError: 'latin-1' codec can't encode character '\u0131' in position 1: ordinal not in range(256)

How can I solve this?

heuer commented 5 years ago

I cannot reproduce the error. Which Python version do you use? Which PyQRCode version do you use?

My code:

>>> import pyqrcode
>>> hexString = "22fd30df7c13fb69f7f87e3a8728f0daf6ab360b82ec9e6d8c1157e19add4013080b3399eff31644e24553e9c30b697078492d9da33bf0a9235ab87a7662398a06c782a31acfc79c5023344b11f3750bb98e500b01"
>>> ansi = bytes.fromhex(hexString ).decode('ANSI')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
LookupError: unknown encoding: ANSI
>>> ansi = bytes.fromhex(hexString ).decode('ISO-8859-1')
>>> ansi
'"ý0ß|\x13ûi÷ø~:\x87(ðÚö«6\x0b\x82ì\x9em\x8c\x11Wá\x9aÝ@\x13\x08\x0b3\x99ïó\x16DâESéÃ\x0bipxI-\x9d£;ð©#Z¸zvb9\x8a\x06Ç\x82£\x1aÏÇ\x9cP#4K\x11óu\x0b¹\x8eP\x0b\x01'
>>> version = 8
>>> scalepermodule = 10
>>> r_image = 'bigcode_r_{}_{}_m.png'.format(version, scalepermodule)
>>> bigcode_r = pyqrcode.create(ansi , error='M', version=version, mode='binary')
>>> bigcode_r.png(r_image, scale=scalepermodule, module_color=(0, 0, 0), background=(0xff, 0, 0))

Result: bigcode_r_8_10_m