When I run the below code in a python script, I'm getting the error message <Response [403]>
But when I send a get request via postman or open up the address in my browser, I'm not getting an error message and it's showing a response status of <200>
I've copied all the headers that are showing up in the network console of Google Chrome to see if perhaps the issue was tied to me not importing all the proper headers, but the issue persists even if after copying every single header.
The code that runs my API
app = FastAPI()
@app.get("/test")
def pass_parameters(parameters: Optional[str] = Query(None)):
file_name = "hey.txt"
with open(file_name, 'w') as f:
api_token = "shdsajkhdjkasjdkasjh3242341jh"
parameters= {"phrase": parameters}
print(parameters)
response = requests.get(f"https://api.state.taxes", headers={ "Accept": "application/json", "Authorization": f"Bearer {api_token}"}, params=parameters)
f.write(json.dumps(response.json(), indent=4))
response = response.json()
return JSONResponse(content=response, media_type="text/json")
if __name__ == '__main__':
uvicorn.run(app, port=8080, host='127.0.0.1')
The code to get stuff from my API
import requests
url = "http://127.0.0.1:8080/test"
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"Connection": "keep-alive",
"Cookie": "AMCV_1B3AA45570643167F000101%40AdobeOrg=-%7CMCIDTS%7C18944%7CMCMID%%7CMCOPTOUT-1636735667s%7CNONE%7CvVersion%7C5.1.1",
"Host": "127.0.0.1:8080",
"If-Modified-Since": "Sat, 19 Mar 2022 15:13:13 GMT",
"If-None-Match": "e6ead9f56bc933ab83465",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "Windows",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36"
}
response = requests.get(url, headers=headers)
print(response) --> returns <Response [403]>
But when I open my browser, the webpage opens up fine with a 200 response in the network console of the developer tools as well as within Postman. I exported the Postman call to Python and getting the same error. I saw several Stackoverflow posts were they were able to fix the issue by applying the correct header and disabling proxy in Postman, I've done both and issue persists. I'm not sure if perhaps there's a header that I'm missing?