Skip to content

Commit

Permalink
Fix AttributeError
Browse files Browse the repository at this point in the history
  • Loading branch information
monosans committed Feb 4, 2024
1 parent a23cf0b commit 419d9fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions proxy_scraper_checker/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)


Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion proxy_scraper_checker/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 419d9fc

Please sign in to comment.