Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community: add trust_env at web_base_loader #28514

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class WebBaseLoader(BaseLoader):
# bs_kwargs = None,
# session = None,
# show_progress = True,
# trust_env = False,
)

Lazy load:
Expand Down Expand Up @@ -128,6 +129,7 @@ def __init__(
session: Any = None,
*,
show_progress: bool = True,
trust_env: bool = False,
ccurme marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
"""Initialize loader.

Expand All @@ -140,6 +142,8 @@ def __init__(
bs_get_text_kwargs: kwargs for beatifulsoup4 get_text
bs_kwargs: kwargs for beatifulsoup4 web page parsing
show_progress: Show progress bar when loading pages.
trust_env: set to True if using proxy to make web requests, for example
using http(s)_proxy environment variables. Defaults to False.
"""
# web_path kept for backwards-compatibility.
if web_path and web_paths:
Expand Down Expand Up @@ -189,6 +193,7 @@ def __init__(
self.continue_on_failure = continue_on_failure
self.autoset_encoding = autoset_encoding
self.encoding = encoding
self.trust_env = trust_env

@property
def web_path(self) -> str:
Expand All @@ -199,7 +204,7 @@ def web_path(self) -> str:
async def _fetch(
self, url: str, retries: int = 3, cooldown: int = 2, backoff: float = 1.5
) -> str:
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(trust_env=self.trust_env) as session:
for i in range(retries):
try:
kwargs: Dict = dict(
Expand Down
Loading