Skip to content

Commit 03ee472

Browse files
committed
Allows Reads from Public Buckets
1 parent 49ce4a8 commit 03ee472

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pandas/io/common.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,23 @@ def get_filepath_or_buffer(
201201
if filepath_or_buffer.startswith("s3n://"):
202202
filepath_or_buffer = filepath_or_buffer.replace("s3n://", "s3://")
203203
fsspec = import_optional_dependency("fsspec")
204-
from botocore.exceptions import NoCredentialsError
204+
205+
# If botocore is installed we fallback to reading with anon=True
206+
# to allow reads from public buckets
207+
try:
208+
import_optional_dependency("botocore")
209+
from botocore.exceptions import ClientError, NoCredentialsError
210+
211+
err_types_to_retry_with_anon = (ClientError, NoCredentialsError)
212+
except ImportError:
213+
err_types_to_retry_with_anon = ()
205214

206215
try:
207216
file_obj = fsspec.open(
208217
filepath_or_buffer, mode=mode or "rb", **(storage_options or {})
209218
).open()
210219
# GH 34626 Reads from Public Buckets without Credentials needs anon=True
211-
except NoCredentialsError:
220+
except err_types_to_retry_with_anon:
212221
if storage_options is None:
213222
storage_options = {"anon": True}
214223
else:

0 commit comments

Comments
 (0)