@@ -178,7 +178,9 @@ def __init__(
178
178
self ._country_code = country_code
179
179
180
180
async def initialize (self ) -> None :
181
- """Load the Apify Proxy password if the API token is provided and check access to Apify Proxy and proxy groups.
181
+ """Check if using proxy, if so, check the access.
182
+
183
+ Load the Apify Proxy password from API (only if not passed to constructor or through env var).
182
184
183
185
Only called if Apify Proxy configuration is used. Also checks if country has access to Apify Proxy groups
184
186
if the country code is provided.
@@ -187,7 +189,17 @@ async def initialize(self) -> None:
187
189
`ProxyConfiguration` instance instead of calling this manually.
188
190
"""
189
191
if self ._uses_apify_proxy :
190
- await self ._maybe_fetch_password ()
192
+ if not self ._password :
193
+ await self ._maybe_fetch_password ()
194
+ if not self ._password :
195
+ raise ValueError (
196
+ 'Apify Proxy password must be provided using the "password" constructor argument '
197
+ f'or the "{ ApifyEnvVars .PROXY_PASSWORD } " environment variable. '
198
+ f'You can also provide your Apify token via the "${ ApifyEnvVars .TOKEN } " environment variable, '
199
+ f'so that the SDK can fetch the proxy password from Apify API, '
200
+ f'when not provided through constructor or ${ ApifyEnvVars .PROXY_PASSWORD } .'
201
+ )
202
+
191
203
await self ._check_access ()
192
204
193
205
async def new_proxy_info (
@@ -255,22 +267,7 @@ async def _maybe_fetch_password(self) -> None:
255
267
user_info = await self ._apify_client .user ().get ()
256
268
if user_info :
257
269
password = user_info ['proxy' ]['password' ]
258
-
259
- if self ._password :
260
- if self ._password != password :
261
- logger .warning (
262
- 'The Apify Proxy password you provided belongs to a different user than the Apify '
263
- 'token you are using. Are you sure this is correct?'
264
- )
265
- else :
266
- self ._password = password
267
-
268
- if not self ._password :
269
- raise ValueError (
270
- 'Apify Proxy password must be provided using the "password" constructor argument '
271
- f'or the "{ ApifyEnvVars .PROXY_PASSWORD } " environment variable. If you add '
272
- f'the "{ ApifyEnvVars .TOKEN } " environment variable, the password will be automatically inferred.'
273
- )
270
+ self ._password = password
274
271
275
272
async def _check_access (self ) -> None :
276
273
proxy_status_url = f'{ self ._configuration .proxy_status_url } /?format=json'
0 commit comments