Naveen
Naveen

Reputation: 1523

AWS: FileNotFoundError: [Errno 2] No such file or directory

I am trying to download a file to sagemaker from my S3 bucket.

the path of the file is s3://vemyone/input/dicom-images-train/1.2.276.0.7230010.3.1.2.8323329.1000.1517875165.878026/1.2.276.0.7230010.3.1.3.8323329.1000.1517875165.878025/1.2.276.0.7230010.3.1.4.8323329.1000.1517875165.878027.dcm

The path of that file is stored as a list element at train_fns[0].

the value of train_fns[0] is

input/dicom-images-train/1.2.276.0.7230010.3.1.2.8323329.1000.1517875165.878026/1.2.276.0.7230010.3.1.3.8323329.1000.1517875165.878025/1.2.276.0.7230010.3.1.4.8323329.1000.1517875165.878027.dcm

I used the following code:

s3 = boto3.resource('s3')
bucketname = 'vemyone'

s3.Bucket(bucketname).download_file(train_fns[0][:], train_fns[0])

but I get the following error:

FileNotFoundError: [Errno 2] No such file or directory: 'input/dicom-images-train/1.2.276.0.7230010.3.1.2.8323329.1000.1517875165.878026/1.2.276.0.7230010.3.1.3.8323329.1000.1517875165.878025/1.2.276.0.7230010.3.1.4.8323329.1000.1517875165.878027.dcm.5b003ba1'

I notice that some characters have appended itself at the end of the path.

how do I solve this problem?

Upvotes: 3

Views: 25300

Answers (1)

gCoh
gCoh

Reputation: 3089

please see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Bucket.download_file

by the doc, first argument is file key, second argument is path for local file:

s3 = boto3.resource('s3')
bucketname = 'vemyone'

s3.Bucket(bucketname).download_file(train_fns[0], '/path/to/local/file')

Upvotes: 3

Related Questions