get a 403 error in python requests while using proxy

I’m trying to access a page with python requests library with proxy.

But i get a 403 error.

I tried different pages and still got the same error.

Also know that my proxy is working well, i tried different correct proxies and still got the same error.(i checked every proxy here)

Here is my code:

import requests
import socket


URL = "www.amazon.com"
HEADER = {
    "Host": URL,
    "ACCEPT-LANGUAGE": "en-US,en;q=0.9,fa-IR;q=0.8,fa;q=0.7,la;q=0.6",
    "USER-AGENT": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
                  "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
}
PROXY = {
    "http": "http://159.8.114.37:8123"
}
IP = socket.gethostbyname(URL)


response = requests.get(f"http://{IP}", headers=HEADER, proxies=PROXY, verify=False)
response.raise_for_status()

The error content:

Traceback (most recent call last):
  File "/Users/ali/Desktop/cdn-detection/main.py", line 27, in <module>
    response.raise_for_status()
  File "/Users/ali/Desktop/cdn-detection/venv/lib/python3.9/site-packages/requests/models.py", line 953, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: http://72.247.161.100/

Answer

Error 403 means forbidden you can find more information about it here https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403

Since your using a proxy too this could mean the page could be blocking proxies (unless its your own page then maybe not). I think its best to switch to a few different proxies and see if the issue persists.