S3上传报错:The XML you provided was not well-formed or did not validate against our published schema

报错:

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

二、我的问题: 

        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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值