Skip to content

Commit b029def

Browse files
author
Adam Klein
committed
need to add a way to override the SSL verify context through the client API
1 parent dac26eb commit b029def

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/apify_client/_http_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import TYPE_CHECKING, Any, Callable
1111

1212
import httpx
13+
from ssl import SSLContext
1314
from apify_shared.utils import ignore_docs, is_content_type_json, is_content_type_text, is_content_type_xml
1415

1516
from apify_client._errors import ApifyApiError, InvalidResponseBodyError, is_retryable_error
@@ -37,6 +38,7 @@ def __init__(
3738
min_delay_between_retries_millis: int = 500,
3839
timeout_secs: int = 360,
3940
stats: Statistics | None = None,
41+
ssl_ctx: SSLContext | str | bool = True,
4042
) -> None:
4143
self.max_retries = max_retries
4244
self.min_delay_between_retries_millis = min_delay_between_retries_millis
@@ -58,8 +60,8 @@ def __init__(
5860
if token is not None:
5961
headers['Authorization'] = f'Bearer {token}'
6062

61-
self.httpx_client = httpx.Client(headers=headers, follow_redirects=True, timeout=timeout_secs)
62-
self.httpx_async_client = httpx.AsyncClient(headers=headers, follow_redirects=True, timeout=timeout_secs)
63+
self.httpx_client = httpx.Client(headers=headers, follow_redirects=True, timeout=timeout_secs, verify=ssl_ctx)
64+
self.httpx_async_client = httpx.AsyncClient(headers=headers, follow_redirects=True, timeout=timeout_secs, verify=ssl_ctx)
6365

6466
self.stats = stats or Statistics()
6567

src/apify_client/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import annotations
2+
from ssl import SSLContext
23

34
from apify_shared.utils import ignore_docs
45

@@ -58,6 +59,7 @@
5859
API_VERSION = 'v2'
5960

6061

62+
6163
class _BaseApifyClient:
6264
http_client: HTTPClient | HTTPClientAsync
6365

@@ -70,6 +72,7 @@ def __init__(
7072
max_retries: int | None = 8,
7173
min_delay_between_retries_millis: int | None = 500,
7274
timeout_secs: int | None = DEFAULT_TIMEOUT,
75+
ssl_ctx: SSLContext | str | bool = True
7376
) -> None:
7477
"""Initialize a new instance.
7578
@@ -87,6 +90,7 @@ def __init__(
8790
self.max_retries = max_retries or 8
8891
self.min_delay_between_retries_millis = min_delay_between_retries_millis or 500
8992
self.timeout_secs = timeout_secs or DEFAULT_TIMEOUT
93+
self.ssl_ctx = ssl_ctx
9094

9195
def _options(self) -> dict:
9296
return {
@@ -109,6 +113,7 @@ def __init__(
109113
max_retries: int | None = 8,
110114
min_delay_between_retries_millis: int | None = 500,
111115
timeout_secs: int | None = DEFAULT_TIMEOUT,
116+
ssl_ctx: SSLContext | str | bool = True
112117
) -> None:
113118
"""Initialize a new instance.
114119
@@ -126,6 +131,7 @@ def __init__(
126131
max_retries=max_retries,
127132
min_delay_between_retries_millis=min_delay_between_retries_millis,
128133
timeout_secs=timeout_secs,
134+
ssl_ctx=ssl_ctx,
129135
)
130136

131137
self.stats = Statistics()
@@ -135,6 +141,7 @@ def __init__(
135141
min_delay_between_retries_millis=self.min_delay_between_retries_millis,
136142
timeout_secs=self.timeout_secs,
137143
stats=self.stats,
144+
ssl_ctx=self.ssl_ctx,
138145
)
139146

140147
def actor(self, actor_id: str) -> ActorClient:

0 commit comments

Comments
 (0)