报错:
botocore.exceptions.ClientError: An error occurred (MalformedXML) when calling the CompleteMultipartUpload operation: The XML you provided was not well-formed or did not validate against our published schema
一、官方回答:
The XML you provided was not well-formed or did not validate against our published schema
-
错误原因:请求中的XML格式非法。
-
解决方案:请根据具体请求进行错误排查。
各请求的详细信息如下:
二、我的问题:
1.原因:with语句块内执行时,所打开的文件没有正确的得到关闭,导致传递过去的参数中找不到文件的或者是文件此时为空状态 。
2.解决:
1.在with语句块内手动添加一行代码,给打开的文件关闭掉:csvfile.close()。
csvfile.close()
bucket_task['key'] = filename
bucket_task['local_path'] = filePath
url = self.S3.run_upload(bucket_task)
2.把以下放到with语句块外。
bucket_task['key'] = filename
bucket_task['local_path'] = filePath
url = self.S3.run_upload(bucket_task)
三、解决后源码:
filename = 'hotel_url_{}.csv'.format(yest_now)
filePath = load + yest_now + '/' + filename
with open(filePath, 'w', newline='') as csvfile:
fieldnames = ['filename', 'url']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for key, value in url_dict.items():
if '.csv' not in key:
url = eval(value)['url']
writer.writerow({'filename': key, 'url': url})
csvfile.close()
bucket_task['key'] = filename
bucket_task['local_path'] = filePath
url = self.S3.run_upload(bucket_task)
创作不易求个赞再走~~~
学习交流QQ:450297392

4328

被折叠的 条评论
为什么被折叠?



