使用boto3从AWS S3存储桶下载-时间戳格式不正确

时间:2019-09-05 12:05:02

标签: python-3.x amazon-s3 boto3

我正在使用boto3库从S3存储桶中检索几个csv:

location = /health {
  return 200;
}

要下载的文件具有一列# Scan s3 verified folder for files s3 = boto3.client('s3', aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key) response = s3.list_objects(Bucket=self.bucket, Prefix='UK_entities/Verified_Matches/') # Ignore first file entry in dict as is just the folder name. Returns a list of files files = response['Contents'][1:] # For any files in /s3/verified/ - download them to local /verified_matches/ for i in range(len(files)): s3.download_file(self.bucket, files[i]['Key'], filepath , os.path.basename(files[i]['Key']))) ,该列只是一个时间戳,并且具有一个值,例如 match_date 这是不正确的。当我从存储桶中手动下载csv时,相同的值显示为 03:44.7

任何人都可以突出显示这里发生的事情,并向我指出如何指定如何处理时间戳的检索吗?

1 个答案:

答案 0 :(得分:0)

我通过指定在上传到S3存储桶之前需要的确切格式来解决此问题。尽管能够以正确的格式从S3手动下载文件,但boto3库始终可以确定格式本身。

from dateutil.tz import gettz
import datetime as dt

# clust_df['match_date'] = pd.to_datetime('today') --> old version
df['match_date'] = dt.datetime.now(gettz()).isoformat()