Code Monkey home page Code Monkey logo

Comments (3)

dlenski avatar dlenski commented on July 19, 2024

I used the zxing online decoder https://zxing.org/w/decode.jspx and it works fine, so I want to know if I'm doing something wrong

It certainly doesn't look like the contents of your barcode are valid UTF-8: a lot of it appears to be horribly mangled.

… or it is a bug.

It's mainly a bug in how the ZXing command-line runner (which this Python module relies on as a wrapper script!) handles its output: namely, it mangles bytes that aren't validly encoded… and the encoding it targets depends on the operating system being used. ☹️ 👎.

On Windows, this mostly works, because the default encoding can reversibly encode and decode unknown bytes, but on Linux it's UTF-8, where certain byte sequences are invalid, and they get mangled by the ZXing Java command-line-runner to an extent that the Python wrapper can't recover them.

See #17 (comment), specifically points (2) and (3) for more thoughts:

  1. The ZXing command-line-runner mangles the output of raw bytes beyond recognition on some operating systems, if they can't be correctly interpreted as UTF-8. For example, the QR code you give as an example gets completely borked on Linux. (I'm guessing you're testing on Windows?) See aff3dde where I added your file as an example, along with some other possible changes:
  2. In order to improve this situation, the ZXing command-line runner would have to be improved to not mangle unknown bytes.

One possible fix for this is #19.

from python-zxing.

dlenski avatar dlenski commented on July 19, 2024

It's possible to use non-default encodings in PDF-17 (and other 2D barcodes like QR or DataMatrix), but you're at the mercy of having encoding and decoding and wrapping software that understands how to do this exactly right… and most of it doesn't.

I'll make the immodest claim that I understand and care about this better than almost anyone in the world, and have contributed code to the Java ZXing library to improve the correctness of its handling of nonstandard character sets (see zxing/zxing#1328, zxing/zxing#1330), but I haven't had time to improve the CommandLineRunner's output.

from python-zxing.

mborus avatar mborus commented on July 19, 2024

I'm coming here because of the same problem - trying to decode example barcodes from Deutsche Bahn (https://www.bahn.de/angebot/regio/barcode, there's a zip folder "Muster-Tickets nach UIC 918.9 (ZIP, 2 MB)"). The Aztec code contains no valid utf-8 - most of it is in zip format. So to process it, the library needs to return the bytes in the raw content to be useful here.

Patching the __init__.py file at line 189 to return the bytes as string like this makes it possible to see the content and it is consistent with barcode scanning apps. (I'm using similar hacks whenever I need to paste the aztec code into web pages)

    try: 
        raw = raw[:-1].decode()
        parsed = parsed[:-1].decode()
    except UnicodeDecodeError:
        raw = ' '.join(f"{i:>02x}" for i in raw[:-1])
        parsed = "" 

It would be useful if an optional parameter switches the raw result to bytes and turns off any parsing attempts.

from python-zxing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.