qrtools.py calls tostring() instead of tobytes()

Bug #1574162 reported by cub
This bug report is a duplicate of:  Bug #1503759: method doesn't work. Edit Remove
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
QR Tools
New
Undecided
Unassigned
python-qrtools (Ubuntu)
New
Undecided
Unassigned

Bug Description

The bug is exposed by the program qtqr, but the root cause is an apparent mismatch between python-qrtools and python-pil that can be fixed with a one-line patch to qrtools.py in python-qrtools.

Below I've given the output of enough commands to fully reproduce my setup. You can use xxd -r to create the same PNG that I used, or you can make your own with qtqr (it won't matter).

$ uname -prs
Linux 4.4.0-21-generic x86_64

$ lsb_release -rd
Description: Ubuntu 16.04 LTS
Release: 16.04

# This is a test QR code that I created with qtqr; as seen below, the content is just "test".
$ xxd test.png
00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR
00000010: 0000 0057 0000 0057 0103 0000 004b 064b ...W...W.....K.K
00000020: 2f00 0000 0650 4c54 4500 0000 ffff ffa5 /....PLTE.......
00000030: d99f dd00 0000 0274 524e 53ff ffc8 b5df .......tRNS.....
00000040: c700 0000 0970 4859 7300 000b 1200 000b .....pHYs.......
00000050: 1201 d2dd 7efc 0000 00ba 4944 4154 388d ....~.....IDAT8.
00000060: cdd3 3b0e c320 0c00 5057 1db2 e504 96b8 ..;.. ..PW......
00000070: 86b7 5c89 5c20 a827 e895 d87c 8d48 bd00 ..\.\ .'...|.H..
00000080: 6c0c 48ae 53a5 c942 ccd8 7a7a 832d 7f10 l.H.S..B..zz.-..
00000090: 2067 c05f 3801 2c84 00ce 7096 ba40 0d62 g._8.,...p..@.b
000000a0: 3aa2 27f4 43c7 0bd5 ae03 63c7 a24d f198 :.'.C.....c..M..
000000b0: a169 9d7f e673 97a6 3512 b9e3 264d a701 .i...s..5...&M..
000000c0: 00d6 c096 85ef 4fae e367 b62b e758 03bb ......O..g.+.X..
000000d0: 3489 e5b2 adb0 e75f 3811 8e03 0289 618d 4......_8.....a.
000000e0: 5c5e 393a c37a 074f eb5e 7b61 6d3a c77b \^9:.z.O.^{am:.{
000000f0: fede b66d 7d5f 583d 751c b4a4 88ed 99dd ...m}_X=u.......
00000100: 839d 654d e61a 8a18 dee6 9ff0 569c e15f ..eM........V.._
00000110: fdb5 b6df 4296 b3b4 dc52 71ee 0000 0000 ....B....Rq.....
00000120: 4945 4e44 ae42 6082 IEND.B`.

$ apt-cache policy zbar-tools
zbar-tools:
  Installed: 0.10+doc-10ubuntu1
  Candidate: 0.10+doc-10ubuntu1
  Version table:
 *** 0.10+doc-10ubuntu1 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        100 /var/lib/dpkg/status

$ zbarimg test.png
QR-Code:test
scanned 1 barcode symbols from 1 images in 0.01 seconds

$ apt-cache policy qtqr
qtqr:
  Installed: 1.4~bzr21-1
  Candidate: 1.4~bzr21-1
  Version table:
 *** 1.4~bzr21-1 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        500 http://us.archive.ubuntu.com/ubuntu xenial/universe i386 Packages
        100 /var/lib/dpkg/status

$ qtqr

### Manually select "Decode" and then "Decode from File" and choose test.png (or any PNG containing a QR code); the operation fails, and the following is printed on the console by qtqr:

/usr/lib/python2.7/dist-packages/PIL/Image.py:870: UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
  'to RGBA images')
Traceback (most recent call last):
  File "/usr/bin/qtqr", line 540, in decodeFile
    if qr.decode():
  File "/usr/lib/python2.7/dist-packages/qrtools.py", line 181, in decode
    raw = pil.tostring()
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 695, in tostring
    "Please call tobytes() instead.")
Exception: tostring() has been removed. Please call tobytes() instead.

$ dpkg --search /usr/lib/python2.7/dist-packages/qrtools.py
python-qrtools: /usr/lib/python2.7/dist-packages/qrtools.py

$ apt-cache policy python-qrtools
python-qrtools:
  Installed: 1.4~bzr21-1
  Candidate: 1.4~bzr21-1
  Version table:
 *** 1.4~bzr21-1 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        500 http://us.archive.ubuntu.com/ubuntu xenial/universe i386 Packages
        100 /var/lib/dpkg/status

$ dpkg --search /usr/lib/python2.7/dist-packages/PIL/Image.py
python-pil:amd64: /usr/lib/python2.7/dist-packages/PIL/Image.py

$ apt-cache policy python-pil
python-pil:
  Installed: 3.1.2-0ubuntu1
  Candidate: 3.1.2-0ubuntu1
  Version table:
 *** 3.1.2-0ubuntu1 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status

Based on the code at Image.py:695, the call to tostring() is obviously an error; I've confirmed that the following patch fixes the problem.

$diff --git a/qrtools.py.orig b/qrtools.py.fixed
index 3e98469..68546e4 100644
--- a/qrtools.py.orig
+++ b/qrtools.py.fixed
@@ -178,7 +178,7 @@ class QR(object):
             # obtain image data
             pil = Image.open(self.filename).convert('L')
             width, height = pil.size
- raw = pil.tostring()
+ raw = pil.tobytes()
             # wrap image data
             image = zbar.Image(width, height, 'Y800', raw)
             # scan the image for barcodes

When this patch is applied to /usr/lib/python2.7/dist-packages/qrtools.py, qtqr is able to correctly decode the test image.

Revision history for this message
cub (cub1975-deactivatedaccount) wrote :

Apparently nobody uses qtqr (not even the developers); otherwise this bug wouldn't have been ignored for over a year.

How do I petition to get this broken package removed from the distribution?

Revision history for this message
Ramiro Algozino (algozino) wrote : Re: [Bug 1574162] Re: qrtools.py calls tostring() instead of tobytes()
Download full text (6.1 KiB)

This has been fixed a while ago in the daily PPA package. Sadly there's no
maintainer for the Debian / Ubuntu's official repositories

El 30 jun. 2017 21:15, "cub" <email address hidden> escribió:

> Apparently nobody uses qtqr (not even the developers); otherwise this
> bug wouldn't have been ignored for over a year.
>
> How do I petition to get this broken package removed from the
> distribution?
>
> --
> You received this bug notification because you are a member of QR Tools
> Team, which is subscribed to QR Tools.
> https://bugs.launchpad.net/bugs/1574162
>
> Title:
> qrtools.py calls tostring() instead of tobytes()
>
> Status in QR Tools:
> New
> Status in python-qrtools package in Ubuntu:
> New
>
> Bug description:
> The bug is exposed by the program qtqr, but the root cause is an
> apparent mismatch between python-qrtools and python-pil that can be
> fixed with a one-line patch to qrtools.py in python-qrtools.
>
> Below I've given the output of enough commands to fully reproduce my
> setup. You can use xxd -r to create the same PNG that I used, or you
> can make your own with qtqr (it won't matter).
>
>
> $ uname -prs
> Linux 4.4.0-21-generic x86_64
>
>
> $ lsb_release -rd
> Description: Ubuntu 16.04 LTS
> Release: 16.04
>
>
> # This is a test QR code that I created with qtqr; as seen below, the
> content is just "test".
> $ xxd test.png
> 00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR
> 00000010: 0000 0057 0000 0057 0103 0000 004b 064b ...W...W.....K.K
> 00000020: 2f00 0000 0650 4c54 4500 0000 ffff ffa5 /....PLTE.......
> 00000030: d99f dd00 0000 0274 524e 53ff ffc8 b5df .......tRNS.....
> 00000040: c700 0000 0970 4859 7300 000b 1200 000b .....pHYs.......
> 00000050: 1201 d2dd 7efc 0000 00ba 4944 4154 388d ....~.....IDAT8.
> 00000060: cdd3 3b0e c320 0c00 5057 1db2 e504 96b8 ..;.. ..PW......
> 00000070: 86b7 5c89 5c20 a827 e895 d87c 8d48 bd00 ..\.\ .'...|.H..
> 00000080: 6c0c 48ae 53a5 c942 ccd8 7a7a 832d 7f10 l.H.S..B..zz.-..
> 00000090: 2067 c05f 3801 2c84 00ce 7096 ba40 0d62 g._8.,...p..@.b
> 000000a0: 3aa2 27f4 43c7 0bd5 ae03 63c7 a24d f198 :.'.C.....c..M..
> 000000b0: a169 9d7f e673 97a6 3512 b9e3 264d a701 .i...s..5...&M..
> 000000c0: 00d6 c096 85ef 4fae e367 b62b e758 03bb ......O..g.+.X..
> 000000d0: 3489 e5b2 adb0 e75f 3811 8e03 0289 618d 4......_8.....a.
> 000000e0: 5c5e 393a c37a 074f eb5e 7b61 6d3a c77b \^9:.z.O.^{am:.{
> 000000f0: fede b66d 7d5f 583d 751c b4a4 88ed 99dd ...m}_X=u.......
> 00000100: 839d 654d e61a 8a18 dee6 9ff0 569c e15f ..eM........V.._
> 00000110: fdb5 b6df 4296 b3b4 dc52 71ee 0000 0000 ....B....Rq.....
> 00000120: 4945 4e44 ae42 6082 IEND.B`.
>
>
> $ apt-cache policy zbar-tools
> zbar-tools:
> Installed: 0.10+doc-10ubuntu1
> Candidate: 0.10+doc-10ubuntu1
> Version table:
> *** 0.10+doc-10ubuntu1 500
> 500 http://us.archive.ubuntu.com/ubuntu xenial/universe amd64
> Packages
> 100 /var/lib/dpkg/status
>
> $ zbarimg test.png
> QR-Code:test
> scanned 1 barcode symbols from 1 images in 0.01 seconds
>
>
> $ apt-cache policy...

Read more...

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.