I am using the script below to download the entirety of an S3 bucket (using the answer from https://stackoverflow.com/users/9806031/konstantinos-katsantonis in Download a folder from S3 using Boto3).
Each object in the bucket is a csv file containing an identical structure: 4 fields. 1 timestamp, 2 strings, 1 float. Always in that order.
import boto3
import botocore
import os
s3 = boto3.resource("s3",
region_name='us-east-2',
aws_access_key_id = '',
aws_secret_access_key = ''
)
bucket_name = '',
s3_folder = '',
local_dir = r''
def download_s3_folder(bucket_name, s3_folder, local_dir):
bucket = s3.Bucket(bucket_name)
for obj in bucket.objects.filter(Prefix=s3_folder):
target = obj.key if local_dir is None \
else os.path.join(local_dir, os.path.relpath(obj.key, s3_folder))
if not os.path.exists(os.path.dirname(target)):
os.makedirs(os.path.dirname(target))
if obj.key[-1] == '/':
continue
bucket.download_file(obj.key, target)
download_s3_folder(bucket_name, s3_folder, local_dir)
When I execute the script, I get the following error. I suspect this is a result of the presence of float.
TypeError: expected string or bytes-like object
What would be the best way to work around this?