rumpeltux / onlineticket Goto Github PK
View Code? Open in Web Editor NEWParser for online-tickets according to ETF-918.3
License: GNU General Public License v3.0
Parser for online-tickets according to ETF-918.3
License: GNU General Public License v3.0
Ich habe ein Ticket der Deutschen Bahn eingelesen, aber die Dekodierung der Daten schlägt immer wieder fehl.
ticket-20220322114631.pdf-007.pbm.txt
.
Der Fehler ist:
Traceback (most recent call last):
File "onlineticket.py", line 572, in
(repr(ot), repr(fixed), ticket, e, f))
NameError: name 'ot' is not defined
Hello @rumpeltux ,
thank you for the updates! The old tickets are now correctly decoded again.
The only problem is that UIC 2.0 tickets are not working. I think this should be a TODO for the future. (I guess it is a lot of work since UIC 2.0 has some fields changes). If you need test data, I'd be happy to give you two tickets I collected.
==== tickets/2023_10_13_ticket
Traceback (most recent call last):
File "onlineticket/onlineticket.py", line 542, in <module>
ot = OT(binary_ticket)
^^^^^^^^^^^^^^^^^
File "onlineticket/onlineticket.py", line 84, in __init__
self.header = self.dict_read(self.generic)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "onlineticket/onlineticket.py", line 116, in dict_read
dat = val[3](self, res)
^^^^^^^^^^^^^^^^^
File "onlineticket/onlineticket.py", line 463, in signature_decode
decoded = asn1.decode(self.read(signature_length))[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 1424, in __call__
raise error.SubstrateUnderrunError(
pyasn1.error.SubstrateUnderrunError: 116<62 at <TagSet object, tags 0:0:9>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "onlineticket/onlineticket.py", line 545, in <module>
fixed = fix_zxing(binary_ticket)
^^^^^^^^^^^^^^^^^^^^^^^^
File "onlineticket/onlineticket.py", line 523, in fix_zxing
data = data.decode('utf-8').encode('latin1')
^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 15-16: invalid continuation byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "onlineticket/onlineticket.py", line 549, in <module>
(repr(ot), repr(fixed), ticket, e, f))
^^^^^
NameError: name 'fixed' is not defined
==== tickets/2023_12_24_ticket
Traceback (most recent call last):
File "onlineticket/onlineticket.py", line 542, in <module>
ot = OT(binary_ticket)
^^^^^^^^^^^^^^^^^
File "onlineticket/onlineticket.py", line 84, in __init__
self.header = self.dict_read(self.generic)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "onlineticket/onlineticket.py", line 116, in dict_read
dat = val[3](self, res)
^^^^^^^^^^^^^^^^^
File "onlineticket/onlineticket.py", line 463, in signature_decode
decoded = asn1.decode(self.read(signature_length))[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 1446, in __call__
raise error.SubstrateUnderrunError('%d-octet short' % (length - len(substrate)))
pyasn1.error.SubstrateUnderrunError: 37-octet short
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "onlineticket/onlineticket.py", line 545, in <module>
fixed = fix_zxing(binary_ticket)
^^^^^^^^^^^^^^^^^^^^^^^^
File "onlineticket/onlineticket.py", line 523, in fix_zxing
data = data.decode('utf-8').encode('latin1')
^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 19: invalid continuation byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "onlineticket/onlineticket.py", line 549, in <module>
(repr(ot), repr(fixed), ticket, e, f))
^^^^^
NameError: name 'fixed' is not defined
When decoding the ticketdump using Windows, the script run in some errors. When using exactly the same ticketdump on Linux, everything works as expected.
onlineticket.txt
Error log:
`
conda create -n python2 python=2.7 anaconda
(python2) C:\Users\PaulBauriegel\Documents\Projekte\onlineticket>python onlineticket.py onlineticket.bin
ORIGINAL: 'OTI010080000060,\x02\x14s\xc3\xaeu\x0f\xc3\xac\xc3\xacjEs7\xc3\x88D^\xc2\x88\xc2\xbd*\xc2\x9cr\xc2\xb3\xc3\x89\x02\x14?T\xc2\xbe\x02H\xc3\x96D\xc2\x9c\xc2\x98\xc3\x81\xc3\xabJ\xc3\xb6\x1c\xc2\x80\x07\xc2\xac'
ZXING: 'OTI010080000060,\x02\x14s\xeeu\x0f\xec\xecjEs7\xc8D^\x88\xbd*\x9cr\xb3\xc9\x02\x14?T\xbe\x02H\xd6D\x9c\x98\xc1\xebJ\xf6\x1c\x80\x07\xac'
onlineticket.bin: Error: 22-octet short (orig); 3-octet short (zxing)
Traceback (most recent call last):
File "onlineticket.py", line 452, in <module>
ots.setdefault(ticket, []).append(OT(fix_zxing(ot)))
File "onlineticket.py", line 60, in __init__
self.header = self.dict_read(self.generic)
File "onlineticket.py", line 92, in dict_read
dat = val[3](self, res)
File "onlineticket.py", line 398, in <lambda>
lambda self, res: decoder.decode(self.read(50))),
File "C:\ProgramData\Anaconda3\envs\python2\lib\site-packages\pyasn1\codec\ber\decoder.py", line 1049, in __call__
raise error.SubstrateUnderrunError('%d-octet short' % (length - len(substrate)))
pyasn1.error.SubstrateUnderrunError: 3-octet short`
Hallo rumpeltux & Co,
erst einmal mein Lob für dieses tolle kleine Projekt! Ich konnte damit erfolgreich mehrere DB-Sparpreise aus 2022 dekodieren. Leider werden aktuelle DB-Sparpreise aus 2024 aber nicht erkannt.
OT
header: b'#UT'
version: b'02'
carrier: b'1080'
key_id: b'00002'
signature: ("PyAsn1Error('<TagSet object, tags 64:0:0> not in asn1Spec: None')", b'@ \xa9rH[...]')
data_length: 201
signature_validity: 'INVALID (asn1 decode error)'
ticket:
0: GenericBlock
head: b'U_FLEX'
version: 13
length: 190
unknown_content: b'b\xb2\x00\x86[...]
Ist dieses Problem bereits bekannt? Welche aktuellen DB-Online-Tickets werden vom Dekoder unterstüzt, vielleicht Flexpreise oder Rail&Fly-Tickets?
Viele Grüße
s21f21
Es wäre hilfreich in der README.md darauf hinzuweisen, dass das Paket imagemagick
installiert sein muss, um den convert
-Befehl in parsepdfs.sh
ausführen zu können.
Ich kann mein Ticket nicht dekodieren.
Ich hoffe es liegt nicht daran, dass:
Ich werde mein Ticket hier nicht öffentlich hochladen, da ich es noch ein paar Monate benutzen muss und nicht gerne modifiziert, etc, hätte, aber werde es über andere Kommunikationswege gerne an Maintainer oder Contributer bereitstellen!
Error log:
Couldn't decode ('data_length', 4, <class 'int'>) b'x\x9cuR' <class '__main__.OT'>
header: b'#UT'
version: b'01'
carrier: b'3306'
key_id: b'00008'
signature: (81490986904044751270006267834755119286057096127, 491087473488507954577434382750464621430406442811)
Traceback (most recent call last):
File "onlineticket.py", line 543, in <module>
ot = OT(binary_ticket)
File "onlineticket.py", line 85, in __init__
self.header = self.dict_read(self.generic)
File "onlineticket.py", line 117, in dict_read
dat = val[3](self, res)
File "onlineticket.py", line 463, in signature_decode
decoded = asn1.decode(self.read(50))[0]
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 1289, in __call__
value, substrate = concreteDecoder.valueDecoder(
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 501, in valueDecoder
asn1Object, trailing = self._decodeComponents(
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 451, in _decodeComponents
component, substrate = decodeFun(substrate, **options)
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 1164, in __call__
raise error.SubstrateUnderrunError(
pyasn1.error.SubstrateUnderrunError: 53<20 at <TagSet object at 0x7f244ce72d30 tags 192:0:2>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "onlineticket.py", line 547, in <module>
ot = OT(fixed)
File "onlineticket.py", line 85, in __init__
self.header = self.dict_read(self.generic)
File "onlineticket.py", line 110, in dict_read
dat = val[2](dat)
ValueError: invalid literal for int() with base 10: b'x\x9cuR'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "onlineticket.py", line 550, in <module>
(repr(ot), repr(fixed), ticket, e, f))
NameError: name 'ot' is not defined
used latest version of repo
txt file from pdf:
I am currently trying to get some data out of the "DeutschlandSemesterTicket" but no open source scanner I tried is capable of that.
the source of the ticket is www.ots-nrw.de
I try to get the time until the ticket is valid, the signature validation and the allowed region
You would help me a lot
Moin!
Würde jemand freundlicherweise einmal nachschauen, warum das Decoding nicht funktioniert?
Ich bin ratlos... :(
Vielen Dank im Voraus! :)
Ps: pycryptodome ist installiert.
Please remove the deprecated python3-crypto package and install python3-pycryptodome instead.
Note: signature verification is disabled due to missing pycryptodome package.
Traceback (most recent call last):
File "onlineticket.py", line 543, in
ot = OT(binary_ticket)
File "onlineticket.py", line 86, in init
self.header = self.dict_read(self.generic)
File "onlineticket.py", line 118, in dict_read
dat = val[3](self, res)
File "onlineticket.py", line 464, in signature_decode
decoded = asn1.decode(self.read(50))[0]
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 1289, in call
value, substrate = concreteDecoder.valueDecoder(
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 501, in valueDecoder
asn1Object, trailing = self._decodeComponents
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 451, in _decodeComponents
component, substrate = decodeFun(substrate, **options)
File "/usr/lib/python3/dist-packages/pyasn1/codec/ber/decoder.py", line 1164, in call
raise error.SubstrateUnderrunError(
pyasn1.error.SubstrateUnderrunError: 58<20 at <TagSet object at 0x7febc30995b0 tags 192:0:2>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "onlineticket.py", line 547, in
ot = OT(fixed)
File "onlineticket.py", line 86, in init
self.header = self.dict_read(self.generic)
File "onlineticket.py", line 118, in dict_read
dat = val[3](self, res)
File "onlineticket.py", line 474, in signature_validity
pubkey = get_pubkey(issuer=res['carrier'],
File "onlineticket.py", line 430, in get_pubkey
for cert_issuer, xid, pubkey in certreader:
ValueError: not enough values to unpack (expected 3, got 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "onlineticket.py", line 550, in
(repr(ot), repr(fixed), ticket, e, f))
NameError: name 'ot' is not defined
Decodierter Aztec-Code (via parsepdfs.sh):
NEXLU4.pdf-001.pbm.txt
At download_keys.py, the shebang #!/usr/bin/env python3
is missing.
Additionally, the executable bit (chmod +x) is missing for this .py file.
The other two .py files correctly have the executable bit set.
Es mag mein Ticket-PDF nicht:
Ticket-2-Print.pdf : image extraction
Syntax Error: Can't get Fields array<0a>
pdfinfo:
Creator: Adobe LiveCycle Designer 11.0
Producer: Adobe XML Form Module Library
CreationDate: Wed Dec 27 13:58:52 2023 CET
ModDate: Wed Dec 27 13:58:52 2023 CET
Custom Metadata: no
Metadata Stream: yes
Tagged: yes
UserProperties: no
Suspects: no
Form: AcroForm
Syntax Error: Can't get Fields array<0a>
JavaScript: no
Pages: 1
Encrypted: no
Page size: 595.276 x 841.89 pts (A4)
Page rot: 0
File size: 114495 bytes
Optimized: no
PDF version: 1.6
Kurze Frage zur Lizenz:
Welche Lizenz hat dieses Projekt? Ich würde gerne eine Fork zur Verarbeitung von ÖBB Tickets erstellen.
Damit das Script auf anhieb funktioniert, müsste die Signatur #!/usr/bin/env python
nach #!/usr/bin/env python3
geändert werden, und import sys
fehlt noch.
Hallo, ich bekomme beim durchführen von sh parsepdfs.sh folgende Fehlermeldung. Was kann ich tun?
sh parsepdfs.sh
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/zxing/NotFoundException
at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:99)Caused by: java.lang.ClassNotFoundException: com.google.zxing.NotFoundException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
I have found out that some of my tickets only work if --zxing
is added, and some of my tickets only work if --zxing
is NOT added.
I would prefer if the script can run mostly automatical, so it could be executed in a batch file. I have changed the code a bit to address that:
for ticket in args.ticket_files:
try:
tickets = [bytes.fromhex(line) for line in open(ticket)]
except:
content = open(ticket, 'rb').read()
tickets = [content]
for line_no, binary_ticket in enumerate(tickets):
logging.info(f'File: {ticket}\tLine: {line_no + 1}')
ot = None
try:
ot = OT(binary_ticket)
except Exception as e:
fixed = fix_zxing(binary_ticket)
ot = OT(fixed)
print(ot)
ots.setdefault(ticket, []).append(ot)
This works so far. If OT(binary_ticket)
fails, then OT(fixed)
will be tested. This code resulted in 100% of my 62 collected being parsed correctly.
Unfortunately, this has a small cosmetic problem remaining:
If ot = OT(binary_ticket)
fails, there will be a STDERR output. How can we avoid that?
WARNING:root:Couldn't decode (('data_length', 4, <class 'int'>), b'\xc3\xa2\xc3\x9e', <class '__main__.OT'>):
header: b'#UT'
version: b'01'
carrier: b'0080'
key_id: b'00007'
signature: ("SubstrateUnderrunError('57<20 at <TagSet object, tags 192:0:3>')", b'0,\x02\x14\x1eI\x06Ll\xc2\x87\xc2\x91O\xc3\x85&\xc2\xb8\xc2\x80m\xc3\xa9\xc3\xb9\x08P\xc2\x87\xc3\x8b#\x02\x145\xc2\x86E\xc2\x9a\xc3\xa2}|\xc3\x9a\x0fV!')
Hallo!
Zuerst einmal vielen Dank für dieses großartige Repository und die gefundenen und zusammengetragenen Informationen! Dennoch ist mir aufgefallen, dass viele Quellenangaben fehlen, die ich durch eigene Recherche gefunden habe und gern beitragen möchte. Fast alle Links führen zum Internet Archive, um von ggf. in der Zukunft zurückgezogenen Dokumenten unabhängig zu sein.
onlineticket.py
verlinkte PDF HandyTicket-Fahrausweise des VRR im VDV-Barcode – Ein Kompendium zur Dekodierung. Der Link im derzeitgen Code ist tot.configure
-Skript mit dem Parameter --enable-build-doc=yes
aufgerufen werden (und dann make
), um die Dokumentation zusätzlich zu der libdbuic2vdvbc.a
zu erstellen. Außerdem sind viele Beispiele und auch Beispieldaten enthalten. Ich finde es fast schon beeindruckend, dass dieser Code unter der BSD-Lizenz steht.A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.