我在多个线程中下载文件,每个线程按流下载。在
def download_file(self, dest:str, filename:str):
r = requests.get(self.url, stream=True, headers={
"Accept": "application/xml",
"Accept-Charset": "utf-8",
"Accept-Language": "pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4",
"Authorization": self.auth
})
with open(f"{dest}/{filename}", 'wb') as f:
total_length = r.headers.get("Content-length")
if not total_length:
f.write(r.content)
else:
for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(int(total_length)/1024) + 1):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()
f.close()
return True
此后,我将这些下载的文件上传到S3存储桶中。在
^{pr2}$问题是,当我试图打开文件上传到S3时,我得到了权限错误。在
[Errno 13] Permission denied: 'C:/Users/User/AppData/Roaming/...'
这不可能是由于多线程(一个线程正在保存,另一个线程试图同时打开),因为我已经尝试禁用多线程,但我得到了相同的错误。我能想到的唯一原因就是“流式下载”。我的同事建议我检查文件中的文件结尾,但是如果我不能打开它,我该怎么做呢?在
目前没有回答
相关问题 更多 >
编程相关推荐