From f94452fa9345d8770e7620c62d58f3844461299a Mon Sep 17 00:00:00 2001 From: daijro Date: Mon, 28 Oct 2024 17:40:42 -0500 Subject: [PATCH] pythonlib: Error handling for invalid addon paths & proxies 0.3.3 Help prevent confusion with using Camoufox addons #55 --- pythonlib/camoufox/addons.py | 4 ++++ pythonlib/camoufox/ip.py | 3 ++- pythonlib/pyproject.toml | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pythonlib/camoufox/addons.py b/pythonlib/camoufox/addons.py index 974e3f1..c172d62 100644 --- a/pythonlib/camoufox/addons.py +++ b/pythonlib/camoufox/addons.py @@ -54,6 +54,10 @@ def confirm_paths(paths: List[str]) -> None: for path in paths: if not os.path.isdir(path): raise InvalidAddonPath(path) + if not os.path.exists(os.path.join(path, 'manifest.json')): + raise InvalidAddonPath( + 'manifest.json is missing. Addon path must be a path to an extracted addon.' + ) def get_open_port() -> int: diff --git a/pythonlib/camoufox/ip.py b/pythonlib/camoufox/ip.py index 50220c4..cca4ac6 100644 --- a/pythonlib/camoufox/ip.py +++ b/pythonlib/camoufox/ip.py @@ -6,7 +6,6 @@ from functools import lru_cache from typing import Dict, Optional, Tuple import requests -from urllib3 import disable_warnings from urllib3.exceptions import InsecureRequestWarning from .exceptions import InvalidIP, InvalidProxy @@ -108,6 +107,8 @@ def public_ip(proxy: Optional[str] = None) -> str: ip = resp.text.strip() validate_ip(ip) return ip + except requests.exceptions.ProxyError as e: + raise InvalidProxy(f"Failed to connect to proxy: {proxy}") from e except (requests.RequestException, InvalidIP): pass raise InvalidIP("Failed to get IP address") diff --git a/pythonlib/pyproject.toml b/pythonlib/pyproject.toml index 811c529..14381ba 100644 --- a/pythonlib/pyproject.toml +++ b/pythonlib/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "camoufox" -version = "0.3.2" +version = "0.3.3" description = "Wrapper around Playwright to help launch Camoufox" authors = ["daijro "] license = "MIT"