|
5 | 5 |
|
6 | 6 | from apify_client._client_registry import ClientRegistry, ClientRegistryAsync |
7 | 7 | from apify_client._consts import ( |
8 | | - API_VERSION, |
9 | 8 | DEFAULT_API_URL, |
10 | 9 | DEFAULT_MAX_RETRIES, |
11 | 10 | DEFAULT_MIN_DELAY_BETWEEN_RETRIES, |
|
72 | 71 | WebhookDispatchCollectionClientAsync, |
73 | 72 | ) |
74 | 73 | from apify_client._statistics import ClientStatistics |
75 | | -from apify_client._utils.http import check_custom_headers |
| 74 | +from apify_client._utils.http import check_custom_headers, to_api_base_url |
76 | 75 | from apify_client.http_clients import HttpClient, HttpClientAsync, ImpitHttpClient, ImpitHttpClientAsync |
77 | 76 | from apify_client.http_compressors._resolve import resolve_compressor |
78 | 77 |
|
@@ -138,9 +137,10 @@ def __init__( |
138 | 137 | [Integrations](https://console.apify.com/account/integrations) page in the Apify Console. |
139 | 138 | api_url: The URL of the Apify API server to connect to. Defaults to https://api.apify.com. It can |
140 | 139 | be an internal URL that is not globally accessible, in which case `api_public_url` should be set |
141 | | - as well. |
| 140 | + as well. The `/v2` API version segment is appended unless the URL path already ends with it. |
142 | 141 | api_public_url: The globally accessible URL of the Apify API server. Should be set only if `api_url` |
143 | | - is an internal URL that is not globally accessible. Defaults to https://api.apify.com. |
| 142 | + is an internal URL that is not globally accessible. Defaults to https://api.apify.com. The `/v2` |
| 143 | + API version segment is appended unless the URL path already ends with it. |
144 | 144 | max_retries: How many times to retry a failed request at most. Set to 0 to disable retries. |
145 | 145 | min_delay_between_retries: How long will the client wait between retrying requests |
146 | 146 | (increases exponentially from this value). |
@@ -171,10 +171,10 @@ def __init__( |
171 | 171 | self._token = token |
172 | 172 | """Apify API token for authentication.""" |
173 | 173 |
|
174 | | - self._base_url = f'{api_url.rstrip("/")}/{API_VERSION}' |
| 174 | + self._base_url = to_api_base_url(api_url) |
175 | 175 | """Base URL of the Apify API.""" |
176 | 176 |
|
177 | | - self._public_base_url = f'{api_public_url.rstrip("/")}/{API_VERSION}' |
| 177 | + self._public_base_url = to_api_base_url(api_public_url) |
178 | 178 | """Public base URL for CDN access.""" |
179 | 179 |
|
180 | 180 | self._statistics = ClientStatistics() |
@@ -261,8 +261,10 @@ def send_request(self, *, method, url, headers, content, timeout, stream) -> Htt |
261 | 261 | Args: |
262 | 262 | token: The Apify API token. It is set as the `Authorization` header on the custom client, |
263 | 263 | unless the client already has one configured. |
264 | | - api_url: The URL of the Apify API server to connect to. Defaults to https://api.apify.com. |
| 264 | + api_url: The URL of the Apify API server to connect to. Defaults to https://api.apify.com. The `/v2` |
| 265 | + API version segment is appended unless the URL path already ends with it. |
265 | 266 | api_public_url: The globally accessible URL of the Apify API server. Defaults to https://api.apify.com. |
| 267 | + The `/v2` API version segment is appended unless the URL path already ends with it. |
266 | 268 | http_client: A custom HTTP client instance extending `HttpClient`. |
267 | 269 | """ |
268 | 270 | instance = cls(token=token, api_url=api_url, api_public_url=api_public_url) |
@@ -514,9 +516,10 @@ def __init__( |
514 | 516 | [Integrations](https://console.apify.com/account/integrations) page in the Apify Console. |
515 | 517 | api_url: The URL of the Apify API server to connect to. Defaults to https://api.apify.com. It can |
516 | 518 | be an internal URL that is not globally accessible, in which case `api_public_url` should be set |
517 | | - as well. |
| 519 | + as well. The `/v2` API version segment is appended unless the URL path already ends with it. |
518 | 520 | api_public_url: The globally accessible URL of the Apify API server. Should be set only if `api_url` |
519 | | - is an internal URL that is not globally accessible. Defaults to https://api.apify.com. |
| 521 | + is an internal URL that is not globally accessible. Defaults to https://api.apify.com. The `/v2` |
| 522 | + API version segment is appended unless the URL path already ends with it. |
520 | 523 | max_retries: How many times to retry a failed request at most. Set to 0 to disable retries. |
521 | 524 | min_delay_between_retries: How long will the client wait between retrying requests |
522 | 525 | (increases exponentially from this value). |
@@ -547,10 +550,10 @@ def __init__( |
547 | 550 | self._token = token |
548 | 551 | """Apify API token for authentication.""" |
549 | 552 |
|
550 | | - self._base_url = f'{api_url.rstrip("/")}/{API_VERSION}' |
| 553 | + self._base_url = to_api_base_url(api_url) |
551 | 554 | """Base URL of the Apify API.""" |
552 | 555 |
|
553 | | - self._public_base_url = f'{api_public_url.rstrip("/")}/{API_VERSION}' |
| 556 | + self._public_base_url = to_api_base_url(api_public_url) |
554 | 557 | """Public base URL for CDN access.""" |
555 | 558 |
|
556 | 559 | self._statistics = ClientStatistics() |
@@ -637,8 +640,10 @@ async def send_request(self, *, method, url, headers, content, timeout, stream) |
637 | 640 | Args: |
638 | 641 | token: The Apify API token. It is set as the `Authorization` header on the custom client, |
639 | 642 | unless the client already has one configured. |
640 | | - api_url: The URL of the Apify API server to connect to. Defaults to https://api.apify.com. |
| 643 | + api_url: The URL of the Apify API server to connect to. Defaults to https://api.apify.com. The `/v2` |
| 644 | + API version segment is appended unless the URL path already ends with it. |
641 | 645 | api_public_url: The globally accessible URL of the Apify API server. Defaults to https://api.apify.com. |
| 646 | + The `/v2` API version segment is appended unless the URL path already ends with it. |
642 | 647 | http_client: A custom HTTP client instance extending `HttpClientAsync`. |
643 | 648 | """ |
644 | 649 | instance = cls(token=token, api_url=api_url, api_public_url=api_public_url) |
|
0 commit comments