Skip to content

Commit 49ce4a8

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

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

pandas/io/common.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,22 @@ 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
205+
206+
try:
207+
file_obj = fsspec.open(
208+
filepath_or_buffer, mode=mode or "rb", **(storage_options or {})
209+
).open()
210+
# GH 34626 Reads from Public Buckets without Credentials needs anon=True
211+
except NoCredentialsError:
212+
if storage_options is None:
213+
storage_options = {"anon": True}
214+
else:
215+
storage_options["anon"] = True
216+
file_obj = fsspec.open(
217+
filepath_or_buffer, mode=mode or "rb", **(storage_options or {})
218+
).open()
204219

205-
file_obj = fsspec.open(
206-
filepath_or_buffer, mode=mode or "rb", **(storage_options or {})
207-
).open()
208220
return file_obj, encoding, compression, True
209221

210222
if isinstance(filepath_or_buffer, (str, bytes, mmap.mmap)):

0 commit comments

Comments
 (0)