【发布时间】:2021-12-15 00:03:28
【问题描述】:
我在包含字段“id”的 s3 位置中有超过 1050 个 json 文件。我正在循环使用 get_object 获取这些 id 的这些 json 文件。我将使用这些 id 并传递一个 url 来获取另一个 json 响应,其中包含一个具有快照位置的字段,即下载文件的链接。我正在捕获下载的对象并使用 s3_client.upload_fileobj(BytesIO(response.content), bucket_name, api_download_file_path + file_name) 写入 s3 位置,但我每次在目标 s3 位置只获得 1000 个 csv 文件我期待 1050。这是由于对 upload_fileobj 的任何限制吗?
完整代码在这里
result = s3_client.list_objects(Bucket=bucket_name, Prefix=api_target_read_path)
for res in result.get('Contents'):
data = s3_client.get_object(Bucket=bucket_name, Key=res.get('Key'))
contents = data['Body'].read().decode('utf-8')
json_data = json.loads(contents)
print(json_data['id'])
json_id = json_data['id']
geturl = inv_avail_get_api_url + json_id
response = requests.get(geturl, headers=headers)
print(response.text)
durl = response.json()["response"]["snapshotLocation"]
response = requests.get(durl)
segments = durl.rpartition('/')
file_name = str(segments[2]).split('?')[0]
print(file_name)
s3_client.upload_fileobj(BytesIO(response.content), bucket_name, api_download_file_path + file_name)
python
【问题讨论】:
标签: python-3.x amazon-web-services amazon-s3 boto3