Невозможно загрузить файл из корзины S3 - PullRequest
0 голосов
/ 08 марта 2020

Я разместил свой код ниже.

Начиная со строки 84, я испытываю трудности с кодированием. Я не могу понять, почему это не позволяет мне загружать PNG в ведре. Я установил разрешения в publi c на полный доступ publi c.

Самая последняя ошибка, которую я получил, была:

"Ошибка клиента (403) при вызове Операция HeadObject: Запрещено "

Любая помощь очень ценится!

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()
...