Questions tagged «boto3»

Boto 3-适用于Python的Amazon Web Services(AWS)SDK

14
Boto3从S3存储桶下载所有文件
我正在使用boto3从s3存储桶获取文件。我需要类似的功能aws s3 sync 我当前的代码是 #!/usr/bin/python import boto3 s3=boto3.client('s3') list=s3.list_objects(Bucket='my_bucket_name')['Contents'] for key in list: s3.download_file('my_bucket_name', key['Key'], key['Key']) 只要存储桶中只有文件,就可以正常工作。如果存储桶中存在文件夹,则抛出错误 Traceback (most recent call last): File "./test", line 6, in <module> s3.download_file('my_bucket_name', key['Key'], key['Key']) File "/usr/local/lib/python2.7/dist-packages/boto3/s3/inject.py", line 58, in download_file extra_args=ExtraArgs, callback=Callback) File "/usr/local/lib/python2.7/dist-packages/boto3/s3/transfer.py", line 651, in download_file extra_args, callback) File "/usr/local/lib/python2.7/dist-packages/boto3/s3/transfer.py", line …


7
模拟boto3 S3客户端方法Python
我正在尝试从boto3 s3客户端对象模拟一个单独的方法来引发异常。但是我需要所有其他方法来使此类正常工作。 这样一来,我可以在执行upload_part_copy并发生错误时测试单个异常测试 第一次尝试 import boto3 from mock import patch with patch('botocore.client.S3.upload_part_copy', side_effect=Exception('Error Uploading')) as mock: client = boto3.client('s3') # Should return actual result o = client.get_object(Bucket='my-bucket', Key='my-key') # Should return mocked exception e = client.upload_part_copy() 但是,这将产生以下错误: ImportError: No module named S3 第二次尝试 查看botocore.client.py源代码后,我发现它做的很聪明,并且该方法upload_part_copy不存在。我发现似乎要打电话给BaseClient._make_api_call我,所以我试图模拟 import boto3 from mock import patch …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.