schwehr / libais

C++ decoder for Automatic Identification System for tracking ships and decoding maritime information
Other
215 stars 94 forks source link

AttributeError: 'NoneType' object has no attribute 'upper' when parsing using tag_block #239

Open andyvan-trabus opened 2 years ago

andyvan-trabus commented 2 years ago

Parsing using the tag_block queue can result in an exception:

python test_239.py Traceback (most recent call last): File "test_239.py", line 9, in queue.put(line, line_no) File "/home/avanpelt/git/TMP/FORK/libais-fork/ais/tag_block.py", line 112, in put match = Parse(line) File "/home/avanpelt/git/TMP/FORK/libais-fork/ais/tag_block.py", line 86, in Parse expected = result['tag_checksum'].upper() AttributeError: 'NoneType' object has no attribute 'upper'

import ais
from ais import tag_block

MESSAGES = ['\\g:1-2-94\\g:2-2-9470,n:11222*1D\\$SAVSI,D13MN-PS-MTEBS1,5,141030.377988,1139,-49,66*58']

queue = tag_block.TagQueue()

for line_no, line in enumerate(MESSAGES):
    queue.put(line, line_no)

while not queue.empty():
    tag_msg = queue.get()
    if "decoded" not in tag_msg:
        print("Message NOT decoded using tag_block queue")
        payload = tag_msg["lines"][0]
        print("payload = '{}'".format(payload))

        body = payload.split(',')[-2]
        pad = int(payload.split('*')[-2][-1])
        print("Calling ais.decode('{}', {})".format(body, pad))
        msg = ais.decode(body, pad)
        print(msg)

    else:
        print("Message decoded using tag_block queue")