File tree 2 files changed +26
-4
lines changed
2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,8 @@ def _strip_schema(url):
16
16
return result .netloc + result .path
17
17
18
18
19
- def get_fs ():
20
- return s3fs .S3FileSystem (anon = False )
19
+ def get_fs (anon = False ):
20
+ return s3fs .S3FileSystem (anon = anon )
21
21
22
22
23
23
def get_file_and_filesystem (
@@ -31,14 +31,14 @@ def get_file_and_filesystem(
31
31
fs = get_fs ()
32
32
try :
33
33
file = fs .open (_strip_schema (filepath_or_buffer ), mode )
34
- except (FileNotFoundError , NoCredentialsError ):
34
+ except (FileNotFoundError , NoCredentialsError , PermissionError ):
35
35
# boto3 has troubles when trying to access a public file
36
36
# when credentialed...
37
37
# An OSError is raised if you have credentials, but they
38
38
# aren't valid for that bucket.
39
39
# A NoCredentialsError is raised if you don't have creds
40
40
# for that bucket.
41
- fs = get_fs ()
41
+ fs = get_fs (anon = True )
42
42
file = fs .open (_strip_schema (filepath_or_buffer ), mode )
43
43
return file , fs
44
44
Original file line number Diff line number Diff line change 1
1
from io import BytesIO
2
+ import os
2
3
3
4
import pytest
4
5
5
6
from pandas import read_csv
7
+ import pandas ._testing as tm
6
8
7
9
from pandas .io .common import is_s3_url
8
10
@@ -23,3 +25,23 @@ def test_streaming_s3_objects():
23
25
for el in data :
24
26
body = StreamingBody (BytesIO (el ), content_length = len (el ))
25
27
read_csv (body )
28
+
29
+
30
+ @tm .network
31
+ @pytest .mark .slow
32
+ def test_read_s3_public ():
33
+ # ensure we can read from a public bucket with credentials
34
+ pytest .importorskip ("s3fs" )
35
+
36
+ with tm .ensure_safe_environment_variables ():
37
+ # temporary workaround as moto fails for botocore >= 1.11 otherwise,
38
+ # see https://github.com/spulec/moto/issues/1924 & 1952
39
+ os .environ .setdefault ("AWS_ACCESS_KEY_ID" , "foobar_key" )
40
+ os .environ .setdefault ("AWS_SECRET_ACCESS_KEY" , "foobar_secret" )
41
+ df = read_csv (
42
+ "s3://gdelt-open-data/events/20130420.export.csv" ,
43
+ nrows = 5 ,
44
+ sep = "\t " ,
45
+ header = None ,
46
+ )
47
+ assert len (df ) == 5
You can’t perform that action at this time.
0 commit comments