From 419d9fc036d0b16f7563eb02b9083cd294c78813 Mon Sep 17 00:00:00 2001 From: monosans Date: Sun, 4 Feb 2024 12:24:12 +0300 Subject: [PATCH] Fix AttributeError --- proxy_scraper_checker/output.py | 5 +++-- proxy_scraper_checker/proxy.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/proxy_scraper_checker/output.py b/proxy_scraper_checker/output.py index d0001a013..ff731b562 100644 --- a/proxy_scraper_checker/output.py +++ b/proxy_scraper_checker/output.py @@ -27,7 +27,8 @@ def _create_proxy_list_str( return "\n".join( proxy.as_str(include_protocol=include_protocol) for proxy in proxies - if not anonymous_only or proxy.host != proxy.exit_ip + if not anonymous_only + or (proxy.exit_ip is not None and proxy.host != proxy.exit_ip) ) @@ -51,7 +52,7 @@ def save_proxies(*, settings: Settings, storage: ProxyStorage) -> None: "exit_ip": proxy.exit_ip, "timeout": round(proxy.timeout, 2), "geolocation": mmdb_reader.get(proxy.exit_ip) - if mmdb_reader is not None + if mmdb_reader is not None and proxy.exit_ip is not None else None, } for proxy in sorted(storage, key=sort.timeout_sort_key) diff --git a/proxy_scraper_checker/proxy.py b/proxy_scraper_checker/proxy.py index 6da2f36e0..8c5a18ee1 100644 --- a/proxy_scraper_checker/proxy.py +++ b/proxy_scraper_checker/proxy.py @@ -35,7 +35,7 @@ class Proxy: username: Optional[str] password: Optional[str] timeout: float = attrs.field(init=False, eq=False) - exit_ip: str = attrs.field(init=False, eq=False) + exit_ip: Optional[str] = attrs.field(init=False, eq=False) async def check(self, *, settings: Settings) -> None: async with settings.semaphore: @@ -67,6 +67,8 @@ async def check(self, *, settings: Settings) -> None: self.exit_ip = parse_ipv4( get_response_text(response=response, content=content) ) + else: + self.exit_ip = None def as_str(self, *, include_protocol: bool) -> str: with StringIO() as buf: