Skip to content

feat: need to add a way to override the SSL verify context through the clie… #400

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions src/apify_client/_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import TYPE_CHECKING, Any, Callable

import httpx
from ssl import SSLContext
from apify_shared.utils import ignore_docs, is_content_type_json, is_content_type_text, is_content_type_xml

from apify_client._errors import ApifyApiError, InvalidResponseBodyError, is_retryable_error
Expand Down Expand Up @@ -37,6 +38,7 @@ def __init__(
min_delay_between_retries_millis: int = 500,
timeout_secs: int = 360,
stats: Statistics | None = None,
ssl_ctx: SSLContext | str | bool = True,
) -> None:
self.max_retries = max_retries
self.min_delay_between_retries_millis = min_delay_between_retries_millis
Expand All @@ -58,8 +60,10 @@ def __init__(
if token is not None:
headers['Authorization'] = f'Bearer {token}'

self.httpx_client = httpx.Client(headers=headers, follow_redirects=True, timeout=timeout_secs)
self.httpx_async_client = httpx.AsyncClient(headers=headers, follow_redirects=True, timeout=timeout_secs)
self.httpx_client = httpx.Client(headers=headers, follow_redirects=True, timeout=timeout_secs, verify=ssl_ctx)
self.httpx_async_client = httpx.AsyncClient(
headers=headers, follow_redirects=True, timeout=timeout_secs, verify=ssl_ctx
)

self.stats = stats or Statistics()

Expand Down
6 changes: 6 additions & 0 deletions src/apify_client/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
from ssl import SSLContext

from apify_shared.utils import ignore_docs

Expand Down Expand Up @@ -70,6 +71,7 @@ def __init__(
max_retries: int | None = 8,
min_delay_between_retries_millis: int | None = 500,
timeout_secs: int | None = DEFAULT_TIMEOUT,
ssl_ctx: SSLContext | str | bool = True,
) -> None:
"""Initialize a new instance.

Expand All @@ -87,6 +89,7 @@ def __init__(
self.max_retries = max_retries or 8
self.min_delay_between_retries_millis = min_delay_between_retries_millis or 500
self.timeout_secs = timeout_secs or DEFAULT_TIMEOUT
self.ssl_ctx = ssl_ctx

def _options(self) -> dict:
return {
Expand All @@ -109,6 +112,7 @@ def __init__(
max_retries: int | None = 8,
min_delay_between_retries_millis: int | None = 500,
timeout_secs: int | None = DEFAULT_TIMEOUT,
ssl_ctx: SSLContext | str | bool = True,
) -> None:
"""Initialize a new instance.

Expand All @@ -126,6 +130,7 @@ def __init__(
max_retries=max_retries,
min_delay_between_retries_millis=min_delay_between_retries_millis,
timeout_secs=timeout_secs,
ssl_ctx=ssl_ctx,
)

self.stats = Statistics()
Expand All @@ -135,6 +140,7 @@ def __init__(
min_delay_between_retries_millis=self.min_delay_between_retries_millis,
timeout_secs=self.timeout_secs,
stats=self.stats,
ssl_ctx=self.ssl_ctx,
)

def actor(self, actor_id: str) -> ActorClient:
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.