Skip to content

[BUG]: AttributeError в фильтре по адресу при указании параметра geo #324

Description

@eminsk

ОС

Windows 11

Версия парсера

v3.2.22

Способ запуска

Docker

Текст ошибки

Traceback (most recent call last):
File "parser_cls.py", line 197, in parse
filtered_ads = self.filter_ads(ads=ads)
File "parser_cls.py", line 252, in filter_ads
return self.ads_filter.apply(ads)
File "filters/ads_filter.py", line 29, in apply
ads = filter_fn(ads)
File "filters/ads_filter.py", line 61, in _filter_by_address
return [ad for ad in ads if self.config.geo in getattr(ad, "geo", {}).get("formattedAddress", "")]
File "filters/ads_filter.py", line 61, in
return [ad for ad in ads if self.config.geo in getattr(ad, "geo", {}).get("formattedAddress", "")]
AttributeError: 'Geo' object has no attribute 'get'

Причина:
Поле ad.geo в модели Pydantic (models.py) является объектом Geo(BaseModel), а не словарем dict. У объектов BaseModel нет метода .get(). Если же ad.geo is None, функция getattr(ad, "geo", {}) возвращает None (а не пустой dict), что приводит к AttributeError: 'NoneType' object has no attribute 'get'.

Исправление в filters/ads_filter.py (строка 61):
return [
ad for ad in ads
if ad.geo and ad.geo.formattedAddress and self.config.geo.lower() in ad.geo.formattedAddress.lower()
]

Логи

2026-09-04 14:10:00.120 | INFO | parser_cls:parse:164 - page=1
2026-09-04 14:10:01.340 | INFO | parser_cls:parse:187 - Объявлений перед фильтрацией 50
2026-09-04 14:10:01.350 | INFO | filters.ads_filter:apply:30 - После фильтрации _filter_viewed осталось 50
2026-09-04 14:10:01.360 | INFO | filters.ads_filter:apply:30 - После фильтрации _filter_by_price_range осталось 50
2026-09-04 14:10:01.370 | ERROR | parser_cls:parse:197 - При фильтрации объявлений произошла ошибка: 'Geo' object has no attribute 'get'
Traceback (most recent call last):
File "filters/ads_filter.py", line 61, in _filter_by_address
return [ad for ad in ads if self.config.geo in getattr(ad, "geo", {}).get("formattedAddress", "")]
AttributeError: 'Geo' object has no attribute 'get'

Конфиг

[avito]
tg_token = ""
tg_chat_id = []
vk_token = ""
vk_user_id = []
urls = [
"https://www.avito.ru/all/gruzoviki_i_spetstehnika/buldozery-ASgBAgICAURU3E0?cd=1"
]
count = 1
keys_word_white_list = []
keys_word_black_list = []
seller_black_list = []
max_price = 99999999
min_price = 0
geo = "Москва"
proxy_string = ""
proxy_change_url = ""
pause_general = 60
pause_between_links = 5
max_age = 0
max_count_of_retry = 5
ignore_reserv = true
ignore_promotion = false
one_time_start = false
one_file_for_link = false
parse_views = false
save_xlsx = true

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions