0

I am trying to read a txt file from public AWS s3 bucket with open()

f= open(url, "r", encoding="utf8")

I made sure the file is publicly accessible However, I still get the error

FileNotFoundError: [Errno 2] No such file or directory 

any suggestions on how to fix it?

m23
  • 21
  • 1
  • 4

1 Answers1

0

open() is looking for the file path locally on your machine.

In order to read from an S3 bucket you could use boto3, the AWS SDK. Something like the below.

import boto3

s3 = boto3.resource('s3')
s3.Bucket(BUCKET_NAME).download_file(PATH, 'FILENAME')

Also see this question for getting the data using requests instead of boto3 (which is arguably simpler)