@@ -202,9 +202,37 @@ def get_filepath_or_buffer(
202
202
filepath_or_buffer = filepath_or_buffer .replace ("s3n://" , "s3://" )
203
203
fsspec = import_optional_dependency ("fsspec" )
204
204
205
- file_obj = fsspec .open (
206
- filepath_or_buffer , mode = mode or "rb" , ** (storage_options or {})
207
- ).open ()
205
+ # If botocore is installed we fallback to reading with anon=True
206
+ # to allow reads from public buckets
207
+ err_types_to_retry_with_anon : List [Any ] = []
208
+ try :
209
+ import_optional_dependency ("botocore" )
210
+ from botocore .exceptions import ClientError , NoCredentialsError
211
+
212
+ err_types_to_retry_with_anon = [
213
+ ClientError ,
214
+ NoCredentialsError ,
215
+ PermissionError ,
216
+ ]
217
+ except ImportError :
218
+ pass
219
+
220
+ try :
221
+ file_obj = fsspec .open (
222
+ filepath_or_buffer , mode = mode or "rb" , ** (storage_options or {})
223
+ ).open ()
224
+ # GH 34626 Reads from Public Buckets without Credentials needs anon=True
225
+ except tuple (err_types_to_retry_with_anon ):
226
+ if storage_options is None :
227
+ storage_options = {"anon" : True }
228
+ else :
229
+ # don't mutate user input.
230
+ storage_options = dict (storage_options )
231
+ storage_options ["anon" ] = True
232
+ file_obj = fsspec .open (
233
+ filepath_or_buffer , mode = mode or "rb" , ** (storage_options or {})
234
+ ).open ()
235
+
208
236
return file_obj , encoding , compression , True
209
237
210
238
if isinstance (filepath_or_buffer , (str , bytes , mmap .mmap )):
0 commit comments