fix(static): exclude block_ads from HTTP request args
block_ads is a browser-engine parameter (used by PlayWright/Camoufox fetchers for ad-domain blocking) and is not recognised by curl_cffi's Session.request(). When the CLI's --ai-targeted flag sets block_ads=True, _merge_request_args forwards it unfiltered, causing: TypeError: Session.request() got an unexpected keyword argument 'block_ads' Add block_ads to the skip_keys set so it is stripped before the dict reaches Session.request(), consistent with existing entries for extra_headers and google_search. Fixes #247
This commit is contained in:
@@ -149,6 +149,7 @@ class _ConfigurationLogic(ABC):
|
||||
# Browser session params (ignored by HTTP sessions)
|
||||
"extra_headers",
|
||||
"google_search",
|
||||
"block_ads",
|
||||
}
|
||||
for k, v in method_kwargs.items():
|
||||
if k not in skip_keys and v is not None:
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
"""Tests for _merge_request_args to ensure browser-only kwargs are excluded.
|
||||
|
||||
Regression tests for https://github.com/D4Vinci/Scrapling/issues/247
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from scrapling.engines.static import FetcherClient
|
||||
|
||||
|
||||
class TestMergeRequestArgsSkipsBrowserParams:
|
||||
"""Verify that browser-only keyword arguments are stripped before
|
||||
the request dict is forwarded to curl_cffi's Session.request()."""
|
||||
|
||||
def _build_args(self, **extra_kwargs):
|
||||
"""Helper: instantiate a FetcherClient and call _merge_request_args."""
|
||||
client = FetcherClient()
|
||||
return client._merge_request_args(url="https://example.com", **extra_kwargs)
|
||||
|
||||
def test_block_ads_excluded(self):
|
||||
"""block_ads is a browser-engine param and must not leak into the
|
||||
HTTP request dict (fixes #247)."""
|
||||
args = self._build_args(block_ads=True)
|
||||
assert "block_ads" not in args
|
||||
|
||||
def test_google_search_excluded(self):
|
||||
"""google_search is a browser-engine param and should be stripped."""
|
||||
args = self._build_args(google_search=True)
|
||||
assert "google_search" not in args
|
||||
|
||||
def test_extra_headers_excluded(self):
|
||||
"""extra_headers is a browser-engine param and should be stripped."""
|
||||
args = self._build_args(extra_headers={"X-Custom": "val"})
|
||||
assert "extra_headers" not in args
|
||||
|
||||
def test_url_present(self):
|
||||
"""The url must always be present in the output dict."""
|
||||
args = self._build_args()
|
||||
assert args["url"] == "https://example.com"
|
||||
|
||||
def test_valid_kwargs_passed_through(self):
|
||||
"""Arbitrary curl_cffi-compatible kwargs should survive."""
|
||||
args = self._build_args(cookies={"session": "abc"})
|
||||
assert args.get("cookies") == {"session": "abc"}
|
||||
Reference in New Issue
Block a user