遇到从S3存储桶下载ZIP文件时的错误。

huangapple go评论98阅读模式
英文:

Having error when downloading the ZIP file from the S3-Bucket

问题

当我尝试从S3存储桶下载ZIP文件时,出现了一些错误。

我的代码

import boto3

client = boto3.client('s3')

bucket = 'picarro-da-gis'
file = 'ReteGasBari/10082021/Incoming/20211008_ReteGasBari.zip'
filename = '/Users/vithushan/Desktop/S3-Downloads/'

# 下载ZIP文件
client.download_file(
    Bucket=bucket,
    Key=file,
    Filename=filename
)

我的错误

File "/Users/vithushan/Desktop/S3-Connect-Automation/zip_download.py", line 12, in <module>
    client.download_file(
  File "/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/boto3/s3/inject.py", line 190, in download_file
    return transfer.download_file(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/boto3/s3/transfer.py", line 326, in download_file
    future.result()
  File "/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/s3transfer/futures.py", line 103, in result
    return self._coordinator.result()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/s3transfer/futures.py", line 266, in result
    raise self._exception
  File "/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/s3transfer/tasks.py", line 139, in __call__
    return this._execute_main(kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/s3transfer/tasks.py", line 162, in _execute_main
    return_value = this._main(**kwargs)
                   ^^^^^^^^^^^^^^^^^^^^
  File "/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/s3transfer/download.py", line 673, in _main
    osutil.rename_file(fileobj.name, final_filename)
  File "/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/s3transfer/utils.py", line 284, in rename_file
    rename_file(current_filename, new_filename)
IsADirectoryError: [Errno 21] Is a directory: '/Users/vithushan/Desktop/S3-Downloads/.b3aAB3c8' -> '/Users/vithushan/Desktop/S3-Downloads/'

可以有人帮助我吗?

我需要通过路径从S3存储桶下载ZIP文件。

英文:

When I am trying to download the ZIP files from the S3 buckets it is showing some error

My Code

import boto3

client = boto3.client(&#39;s3&#39;)

bucket = &#39;picarro-da-gis&#39;
file = &#39;ReteGasBari/10082021/Incoming/20211008_ReteGasBari.zip&#39;
filename = &#39;/Users/vithushan/Desktop/S3-Downloads/&#39;

# Downloading ZIP file
client.download_file(
    Bucket=bucket,
    Key=file,
    Filename=filename
)

My error

File &quot;/Users/vithushan/Desktop/S3-Connect-Automation/zip_download.py&quot;, line 12, in &lt;module&gt;
    client.download_file(
  File &quot;/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/boto3/s3/inject.py&quot;, line 190, in download_file
    return transfer.download_file(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File &quot;/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/boto3/s3/transfer.py&quot;, line 326, in download_file
    future.result()
  File &quot;/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/s3transfer/futures.py&quot;, line 103, in result
    return self._coordinator.result()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File &quot;/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/s3transfer/futures.py&quot;, line 266, in result
    raise self._exception
  File &quot;/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/s3transfer/tasks.py&quot;, line 139, in __call__
    return self._execute_main(kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File &quot;/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/s3transfer/tasks.py&quot;, line 162, in _execute_main
    return_value = self._main(**kwargs)
                   ^^^^^^^^^^^^^^^^^^^^
  File &quot;/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/s3transfer/download.py&quot;, line 673, in _main
    osutil.rename_file(fileobj.name, final_filename)
  File &quot;/Users/vithushan/Desktop/S3-Connect-Automation/s3-Env/lib/python3.11/site-packages/s3transfer/utils.py&quot;, line 284, in rename_file
    rename_file(current_filename, new_filename)
IsADirectoryError: [Errno 21] Is a directory: &#39;/Users/vithushan/Desktop/S3-Downloads/.b3aAB3c8&#39; -&gt; &#39;/Users/vithushan/Desktop/S3-Downloads/&#39;

Can anyone help for me?

I need to download the ZIP file from the S3 bucket using path

答案1

得分: 1

Your filename points to a directory. You need to add a specific filename for the downloaded object:

import boto3

client = boto3.client('s3')

bucket = 'picarro-da-gis'
file = 'ReteGasBari/10082021/Incoming/20211008_ReteGasBari.zip'
filename = '/Users/vithushan/Desktop/S3-Downloads/downloaded.zip'

# Downloading ZIP file
client.download_file(
    Bucket=bucket,
    Key=file,
    Filename=filename
)
英文:

Your filename points to a directory. You need to add a specific filename for the downloaded object:

import boto3

client = boto3.client(&#39;s3&#39;)

bucket = &#39;picarro-da-gis&#39;
file = &#39;ReteGasBari/10082021/Incoming/20211008_ReteGasBari.zip&#39;
filename = &#39;/Users/vithushan/Desktop/S3-Downloads/downloaded.zip&#39;

# Downloading ZIP file
client.download_file(
    Bucket=bucket,
    Key=file,
    Filename=filename
)

huangapple
  • 本文由 发表于 2023年8月4日 21:07:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76836218.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定