无法从S3存储桶下载文件

时间:2020-03-08 03:27:00

标签: python amazon-web-services amazon-s3 download boto3

我在下面发布了我的代码。

从第84行开始,我很难进行编码。我无法弄清楚为什么它不允许我在存储桶中下载PNG。我已将公开权限设置为完全公开访问。

我最近遇到的错误是:

“调用HeadObject操作时发生客户端错误(403):禁止”

非常感谢您的协助!

import logging
import boto3
import pprint
import math
import os
import botocore
from botocore.exceptions import ClientError

def mainMenu(): 
    print("1. Are you looking for a coach? Here is their contact data.")
    print("2. Are you a beginner? Select 2 for your exersises.")
    print("3. Are you some where in the middle of your journey? Select 3 for your exersises.")
    print("4. Are you more Advanced? Select 4 for your exersises.")
    print("5. Are you hardcore and love to workout? Select 5.")
    print("6. Look at progress photos here!")
    print("7. Quit")   

    selection=int(input("Lets lose weight together!!! Please Select a Number:"))
    if selection==1: 
       coach()
    elif selection==2:
         beginner()
    elif selection==3: 
        intermediate()
    elif selection==4: 
       advanced()
    elif selection==5: 
        hardcore()
    elif selection==6: 
        progress_Photos()
    elif selection==7: 
        exit()
    else:
        print("Invalid choice. Enter 1-7")
        while selection == 7:
            break

    selection=int(input("Lets lose weight together!!! Please Select a Number:"))
"""Selection number 1 Input user data into DynamoDB database """
def coach():
       dynamodb = boto3.resource("dynamodb")
       table = dynamodb.Table('coachdata')
       response = table.scan()
       pprint.pprint(response, depth=3, compact = True)

"""Selection number 2 Calculate exersises for beginners """     
def beginner():
    poundsToLose = input("How many beginner pounds would you like to lose this month? ")
    poundsToLose = int(poundsToLose)
    pushupexersises = (poundsToLose * 2)
    situpexersises = (poundsToLose * 10)
    plankexersises = (poundsToLose * 5)
    print ("To lose {} pound this month do {} pushups {} situps and {} planks every day.".format(poundsToLose,pushupexersises,situpexersises,plankexersises))

"""Selection number 3 Calculate exersises for intermediate users"""      
def intermediate():
    poundsToLose = input("How many intermediate pounds would you like to lose this month? ")
    poundsToLose = int(poundsToLose)
    pushupexersises = (poundsToLose * 5)
    situpexersises = (poundsToLose * 15)
    plankexersises = (poundsToLose * 10)
    print ("To lose {} pound this month do {} pushups {} situps and {} planks every day.".format(poundsToLose,pushupexersises,situpexersises,plankexersises))

"""Selection number 4 Calculate exersises for advanced users"""
def advanced():
    poundsToLose = input("How many advanced pounds would you like to lose this month? ")
    poundsToLose = int(poundsToLose)
    pushupexersises = (poundsToLose * 10)
    situpexersises = (poundsToLose * 20)
    plankexersises = (poundsToLose * 15)
    print ("To lose {} pound this month do {} pushups {} situps and {} planks every day.".format(poundsToLose,pushupexersises,situpexersises,plankexersises))

"""Selection number 5 Calculate exersises for hardcore users"""   
def hardcore():
    poundsToLose = input("How many HARDCORE pounds would you like to lose this month? ")
    poundsToLose = int(poundsToLose)
    pushupexersises = (poundsToLose * 20)
    situpexersises = (poundsToLose * 40)
    plankexersises = (poundsToLose * 30)
    print ("To lose {} pound this month do {} pushups {} situps and {} planks every day.".format(poundsToLose,pushupexersises,situpexersises,plankexersises))


"""Selection number upload progress photos to S3 """     
def progress_Photos():
    """Retrieve an object from an Amazon S3 bucket

    :param bucket_name: string
    :param object_name: string
    :return: botocore.response.StreamingBody object. If error, return None.
    """

    # Retrieve the object
    s3 = boto3.client('s3')
    try:
        response = s3.get_object(Bucket='edu.umuc.sdev400.rharner.letsworkout', Key='beforeandafter.PNG' )
    except ClientError as e:
        # AllAccessDisabled error == bucket or object not found
        logging.error(e)


if __name__ == '__main__':
    mainMenu()

0 个答案:

没有答案