403 Forbidden Error when calling an AWS API Gateway in Python

0

I set up a REST API in AWS with a PUT method to upload files to an S3 bucket. The "Authorization" field in the Method Request is set to NONE. I'm calling the API in Python like so:

    file = {"file": open('file.jpg', 'rb')}
    
    requests.put(https://api-id.execute-api.us-east-1.amazonaws.com/Prod/bucketname/filename, files=file) 

However, each time this command runs, it returns the error:

    "403 Client Error: Forbidden for url: https://api-id.execute-api.us-east-1.amazonaws.com/Prod/bucketname/filename"

This doesn't make sense to me; authorization is set to NONE, so anybody should be able to call the API - why am I getting "Forbidden"? Also, the request works perfectly fine in Postman - I am able to call the API and upload the file and it returns "200 Successful".

I've searched other posts on Google and StackOverflow to no avail. What is going on?

TobyP
已提問 5 年前檢視次數 1841 次
1 個回答
1

Figured it out, I was sending Binary files up to the gateway without adding those file types to the "Binary File Types" section in Settings. For some reason this resulted in a 403 Forbidden Error (even though it wasn't an authentication issue at all).

TobyP
已回答 5 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南