diff --git a/src/lbc/client.py b/src/lbc/client.py index 89886fc..0a36334 100644 --- a/src/lbc/client.py +++ b/src/lbc/client.py @@ -21,7 +21,7 @@ class Client(Session): timeout (int, optional): Maximum time in seconds to wait for a request before timing out. Defaults to 30. max_retries (int, optional): Maximum number of times to retry a request in case of failure (403 error). Defaults to 5. """ - super().__init__(proxy=proxy, impersonate=impersonate) + super().__init__(proxy=proxy, impersonate=impersonate, request_verify=request_verify) self.request_verify = request_verify self.timeout = timeout @@ -36,7 +36,7 @@ class Client(Session): url (str): Full URL of the API endpoint. payload (Optional[dict], optional): JSON payload to send with the request. Used for POST/PUT methods. Defaults to None. timeout (int, optional): Timeout for the request, in seconds. Defaults to 30. - max_retries (int, optional): Number of times to retry the request in case of failure. Defaults to 3. + max_retries (int, optional): Number of times to retry the request in case of failure. Defaults to 5. Raises: DatadomeError: Raised when the request is blocked by Datadome protection (HTTP 403). @@ -56,7 +56,7 @@ class Client(Session): return response.json() elif response.status_code == 403: if max_retries > 0: - self.session = self._init_session(self._proxy, self._impersonate) # Re-init session + self.session = self._init_session(proxy=self._proxy, impersonate=self._impersonate, request_verify=self.request_verify) # Re-init session return self._fetch(method=method, url=url, payload=payload, timeout=timeout, max_retries=max_retries - 1) if self.proxy: raise DatadomeError(f"Access blocked by Datadome: your proxy appears to have a poor reputation, try to change it.") diff --git a/src/lbc/session.py b/src/lbc/session.py index 1c3f644..5107115 100644 --- a/src/lbc/session.py +++ b/src/lbc/session.py @@ -5,12 +5,12 @@ from typing import Optional import random class Session: - def __init__(self, proxy: Optional[Proxy] = None, impersonate: BrowserTypeLiteral = None): - self._session = self._init_session(proxy=proxy, impersonate=impersonate) + def __init__(self, proxy: Optional[Proxy] = None, impersonate: BrowserTypeLiteral = None, request_verify: bool = True): + self._session = self._init_session(proxy=proxy, impersonate=impersonate, request_verify=request_verify) self._proxy = proxy self._impersonate = impersonate - def _init_session(self, proxy: Optional[Proxy] = None, impersonate: BrowserTypeLiteral = None) -> requests.Session: + def _init_session(self, proxy: Optional[Proxy] = None, impersonate: BrowserTypeLiteral = None, request_verify: bool = True) -> requests.Session: """ Initializes an HTTP session with optional proxy configuration and browser impersonation. @@ -19,7 +19,8 @@ class Session: Args: proxy (Optional[Proxy], optional): Proxy configuration to use for the session. If provided, it will be applied to both HTTP and HTTPS traffic. Defaults to None. impersonate (BrowserTypeLiteral, optional): Browser type to impersonate for requests (e.g., "firefox", "chrome", "edge", "safari", "safari_ios", "chrome_android"). If None, a random browser type will be chosen. - + request_verify (bool, optional): Whether to verify SSL certificates for HTTPS requests. Defaults to True. + Returns: requests.Session: A configured session instance ready to send requests. """ @@ -53,7 +54,7 @@ class Session: "https": proxy.url } - session.get("https://www.leboncoin.fr/") # Init cookies + session.get("https://www.leboncoin.fr/", verify=request_verify) # Init cookies return session