Skip to content
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
13 changes: 13 additions & 0 deletions src/apify/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ def _raise_if_not_initialized(self) -> None:
if not self._is_initialized:
raise RuntimeError('The Actor was not initialized!')

def _raise_if_cloud_requested_but_not_configured(self, *, force_cloud: bool) -> None:
if not force_cloud:
return

if not self.is_at_home() and self.config.token is None:
raise RuntimeError(
'In order to use the Apify cloud storage from your computer, '
'you need to provide an Apify token using the APIFY_TOKEN environment variable.'
)

async def init(self) -> None:
"""Initialize the Actor instance.

Expand Down Expand Up @@ -335,6 +345,7 @@ async def open_dataset(
An instance of the `Dataset` class for the given ID or name.
"""
self._raise_if_not_initialized()
self._raise_if_cloud_requested_but_not_configured(force_cloud=force_cloud)

return await Dataset.open(
id=id,
Expand Down Expand Up @@ -367,6 +378,7 @@ async def open_key_value_store(
An instance of the `KeyValueStore` class for the given ID or name.
"""
self._raise_if_not_initialized()
self._raise_if_cloud_requested_but_not_configured(force_cloud=force_cloud)

return await KeyValueStore.open(
id=id,
Expand Down Expand Up @@ -401,6 +413,7 @@ async def open_request_queue(
An instance of the `RequestQueue` class for the given ID or name.
"""
self._raise_if_not_initialized()
self._raise_if_cloud_requested_but_not_configured(force_cloud=force_cloud)

return await RequestQueue.open(
id=id,
Expand Down
Loading