Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Deal with unknown buckets, fix path expectation
  • Loading branch information
PGijsbers committed Feb 18, 2021
commit b4ed9558fb1d3a6108a8955bc20c31eb6412d09a
20 changes: 12 additions & 8 deletions openml/_api_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,25 @@ def _download_minio_file(
destination = pathlib.Path(destination)
parsed_url = urllib.parse.urlparse(source)

# expect path format: /minio/BUCKET/path/to/file.ext
if not str(parsed_url.path).startswith("/minio/"):
raise ValueError(f"Expect start of path of source is '/minio/', found '{parsed_url.path}'")

bucket, object_name = parsed_url.path[len("/minio/") :].split("/", maxsplit=1)
# expect path format: /BUCKET/path/to/file.ext
bucket, object_name = parsed_url.path[1:].split("/", maxsplit=1)
if destination.is_dir():
destination = pathlib.Path(destination, object_name)
if destination.is_file() and not exists_ok:
raise FileExistsError(f"File already exists in {destination}.")

client = minio.Minio(endpoint=parsed_url.netloc, secure=False,)
Comment thread
mfeurer marked this conversation as resolved.
Outdated

file_meta = client.fget_object(
bucket_name=bucket, object_name=object_name, file_path=str(destination),
)
try:
file_meta = client.fget_object(
bucket_name=bucket, object_name=object_name, file_path=str(destination),
)
except minio.error.S3Error as e:
if e.message.startswith("Object does not exist"):
raise FileNotFoundError(f"Object at '{source}' does not exist.") from e
# e.g. permission error, or a bucket does not exist (which is also interpreted as a
# permission error on minio level).
raise FileNotFoundError("Bucket does not exist or is private.") from e
return file_meta
Comment thread
mfeurer marked this conversation as resolved.
Outdated


Expand Down