csparpa / pyowm

A Python wrapper around the OpenWeatherMap web API
https://pyowm.readthedocs.io
MIT License
790 stars 172 forks source link

AssertionError: Event sender name must be specified #408

Closed Touyu-Pan closed 1 year ago

Touyu-Pan commented 1 year ago

Problem

I tried to use one_call method to fetch the forecast info for this loaction lat: 55.761665, lon: 37.606667 ( Moscow, RU )

I got this error message

  File "/Users/jeff/data3p/.venv/lib/python3.10/site-packages/pyowm/weatherapi25/weather_manager.py", line 532, in one_call
    return one_call.OneCall.from_dict(json_data)
  File "/Users/jeff/data3p/.venv/lib/python3.10/site-packages/pyowm/weatherapi25/one_call.py", line 100, in from_dict
    alerts = [NationalWeatherAlert.from_dict(item) for item in the_dict['alerts']]
  File "/Users/jeff/data3p/.venv/lib/python3.10/site-packages/pyowm/weatherapi25/one_call.py", line 100, in <listcomp>
    alerts = [NationalWeatherAlert.from_dict(item) for item in the_dict['alerts']]
  File "/Users/jeff/data3p/.venv/lib/python3.10/site-packages/pyowm/weatherapi25/national_weather_alert.py", line 105, in from_dict
    return NationalWeatherAlert(sender, title, description, start_time, end_time, tags)
  File "/Users/jeff/data3p/.venv/lib/python3.10/site-packages/pyowm/weatherapi25/national_weather_alert.py", line 33, in __init__
    assert sender, 'Event sender name must be specified'
AssertionError: Event sender name must be specified

How to reproduce this bug

mgr.one_call(lat=55.761665, lon=37.606667)

pyowm version: 3.3.0 ( latest ) python version: 3.10.6

lucemia commented 1 year ago

In this case, the return data's sender name is empty string.

[
    {
        "sender_name": "",
        "event": "Other dangers",
        "start": 1674097200,
        "end": 1674241200,
        "description": "",
        "tags": [],
    },
    {
        "sender_name": "",
        "event": "Прочие опасности",
        "start": 1674097200,
        "end": 1674241200,
        "description": "Гололедица.",
        "tags": [],
    },
    {
        "sender_name": "",
        "event": "Wind",
        "start": 1674097200,
        "end": 1674129600,
        "description": "",
        "tags": ["Wind"],
    },
    {
        "sender_name": "",
        "event": "Ветер",
        "start": 1674097200,
        "end": 1674129600,
        "description": "Местами порывы до 17 м/с.",
        "tags": ["Wind"],
    },
    {
        "sender_name": "",
        "event": "Freezing rain, icing",
        "start": 1674097200,
        "end": 1674108000,
        "description": "",
        "tags": ["Extreme temperature value", "Rain", "Black ice"],
    },
    {
        "sender_name": "",
        "event": "Гололедно - изморозевое отложение",
        "start": 1674097200,
        "end": 1674108000,
        "description": "Слабый гололед",
        "tags": ["Black ice"],
    },
]
Harmon758 commented 1 year ago

This was a duplicate of #399, and was already fixed with https://github.com/csparpa/pyowm/commit/f27876f5d679254b709f8a7ac9998c23ff02a289 in the develop branch, which also fixed handling for empty event description strings.