Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

METAR request causes crash #23

Closed
chuchel opened this issue Apr 10, 2024 · 12 comments · Fixed by #24
Closed

METAR request causes crash #23

chuchel opened this issue Apr 10, 2024 · 12 comments · Fixed by #24
Assignees
Labels
bug Something isn't working

Comments

@chuchel
Copy link

chuchel commented Apr 10, 2024

I started up an instance on a Raspbery Pi (named mpad2 in case you see the traffic) and a buddy was helping me test it. He requested METARs and the script died. I fired it up again, and was able to replicate the issue with a different METAR request.

2024-04-09 20:34:42,236 aprs_listener -INFO- {'latitude': 32.42417, 'longitude': -97.35533, 'altitude': 0.0, 'lasttime': datetime.datetime(2024, 3, 2, 15, 33), 'comment': None, 'when': 'today', 'when_daytime': 'day', 'what': 'metar', 'units': 'imperial', 'message_callsign': 'S', 'users_callsign': 'KI7JOM-10', 'language': 'en', 'icao': None, 'human_readable_message': None, 'date_offset': 0, 'hour_offset': -1, 'satellite': None, 'repeater_band': None, 'repeater_mode': None, 'city': None, 'state': None, 'country': None, 'country_code': None, 'county': None, 'district': None, 'address': None, 'zipcode': None, 'cwop_id': None, 'street': None, 'street_number': None, 'users_latitude': 0.0, 'users_longitude': 0.0, 'number_of_results': 1, 'osm_special_phrase': None, 'dapnet_message': None, 'mail_recipient': None, 'force_outgoing_unicode_messages': False}
2024-04-09 20:34:42,236 output_generator -INFO- Running output worker generate_output_message_metar()
2024-04-09 20:34:42,848 inet -ERROR- APRS Packet: b'KI7JOM-10>APSAR,WIDE2-2,qAO,WWU::MPAD2    :metars bli{06'
Traceback (most recent call last):
  File "/home/chris/mpad/src/./aprs_listener.py", line 584, in <module>
    AIS.consumer(mycallback, blocking=True, immortal=True, raw=False)
  File "/home/chris/.local/lib/python3.11/site-packages/aprslib/inet.py", line 185, in consumer
    callback(self._parse(line))
  File "/home/chris/mpad/src/./aprs_listener.py", line 306, in mycallback
    success, output_message = generate_output_message(
                              ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chris/mpad/src/output_generator.py", line 107, in generate_output_message
    success, output_list = generate_output_message_metar(
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chris/mpad/src/output_generator.py", line 322, in generate_output_message_metar
    success, metar_response = get_metar_data(
                              ^^^^^^^^^^^^^^^
  File "/home/chris/mpad/src/airport_data_modules.py", line 198, in get_metar_data
    pos = meintext.find(icao_code)
          ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: must be str, not NoneType

Did I break it, or was it broken when I pulled it?

@joergschultzelutter joergschultzelutter self-assigned this Apr 10, 2024
@joergschultzelutter
Copy link
Owner

I will look into this matter later on this evening. When did you pull the code - recently or a few weeks ago? Release https://github.com/joergschultzelutter/mpad/releases/tag/0.42 contains several changes related to METAR / TAF data.

For testing, you can use the included "parser_test" script: https://github.com/joergschultzelutter/mpad/blob/master/src/parser_test.py. This will enable the general parser and output generator without sending any content to APRS.

@chuchel
Copy link
Author

chuchel commented Apr 10, 2024 via email

@joergschultzelutter joergschultzelutter added the bug Something isn't working label Apr 10, 2024
@joergschultzelutter
Copy link
Owner

Thanks. From what I can tell from your log file, you tried to submit the command string "metars bli" via the parser, right?

I tried to reproduce the issue, but to no avail:

mpad – parser_test py 2024-04-10 20-29-20

Nevertheless, I will add some safety measures to the current code and will create a new release - presumably not later than Saturday.

@chuchel
Copy link
Author

chuchel commented Apr 10, 2024 via email

@chuchel
Copy link
Author

chuchel commented Apr 10, 2024 via email

@joergschultzelutter
Copy link
Owner

I didn't expect things to be different; even though my Prod instance uses a fairly old BS4 version, my Dev envonment uses BS4's latest code version.

Nevertheless, the code should have been able to pull the METAR data based on your call sign's location. Not sure if you're facing a local network issue here. But I will add some safety layer to the code, thus prveventing it to crash in case no content gets returned from the source web site.

@chuchel
Copy link
Author

chuchel commented Apr 11, 2024 via email

@joergschultzelutter
Copy link
Owner

I think I know what the problem is.

2024-04-09 20:34:42,236 aprs_listener -INFO- {'latitude': 32.42417, 'longitude': -97.35533, 'altitude': 0.0, 'lasttime': datetime.datetime(2024, 3, 2, 15, 33), 'comment': None, 'when': 'today', 'when_daytime': 'day', 'what': 'metar', 'units': 'imperial', 'message_callsign': 'S', 'users_callsign': 'KI7JOM-10', 'language': 'en', 'icao': None, 'human_readable_message': None, 'date_offset': 0, 'hour_offset': -1, 'satellite': None, 'repeater_band': None, 'repeater_mode': None, 'city': None, 'state': None, 'country': None, 'country_code': None, 'county': None, 'district': None, 'address': None, 'zipcode': None, 'cwop_id': None, 'street': None, 'street_number': None, 'users_latitude': 0.0, 'users_longitude': 0.0, 'number_of_results': 1, 'osm_special_phrase': None, 'dapnet_message': None, 'mail_recipient': None, 'force_outgoing_unicode_messages': False}

here's the issue in question:
'icao': None

It seems as if the program was unable to determine the airport code that is closest to your call sign's location. Therefore, all other sub steps fail. I will aadd a few precautions to the code calling the Metar data. This will obviously not solve the issue with the missing airport information but will should no longer crash the program 😄

@chuchel
Copy link
Author

chuchel commented Apr 11, 2024 via email

@joergschultzelutter
Copy link
Owner

I've just released version 0.43. The only piece of code that you need to swap is the airport_data_modules.py code. If you intend to test the code, feel free to pull the parser_test.py module as well which will act as 'offline console', meaning that whatever you feed into that module as input text should reflect the message that you would get via radio. So if this code survives erroneous input, so will the production version (fingers crossed 😄 )

Some additional notes:

  • In case you never started the bot 'as is', it probably never created the initial databases for you. Please check if the src/data_files directory contains a file called airport_stations.txt - I bet that this file is either missing OR is empty - which would explain why your local instance fails the lookup. You need to have that file installed.
    I've added a local copy, but you can have the file created via update_local_airport_stations_file from the airport_data_modules.py module.

Related to your question, the METAR code gets triggered by the output_generator.py file (function: generate_output_message_metar)

Hope this helps!
Joerg

@chuchel
Copy link
Author

chuchel commented Apr 12, 2024 via email

@joergschultzelutter
Copy link
Owner

I've created release 0.51 and suggest to use this release over 0.43.

Among many changes, the parser_test.py file will now detect any missing local files and download them for you. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants