Forums

Getting the Error 403: Forbidden

hi, i have a code on here and i upgraded the account already and i'm getting the Error 403: Forbidden.

here is the part of the code

Am I doing something wrong?

def get_price_parts(url):
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.81 Safari/537.36',
    'Authorization': 'Token {}'.format(token)
}

try:
    # Fetch the content of the URL with a custom User-Agent
    response = requests.get(url, headers=headers)
    response.raise_for_status()  # Raise an error for bad responses

    # Parse the HTML content with BeautifulSoup
    soup = BeautifulSoup(response.text, 'html.parser')

.

Check out https://help.pythonanywhere.com/pages/403ForbiddenError/

I already checked, I read that if I have paid account I don’t need to use proxy but it still doesn’t work. I tried with scraperAPI token and proxy and it works

Glad it works now -- just out of curiosity: how did you run your code? If in a console, did you start a fresh one after upgrading?

I ran the code normally but if you know to make it work without any third party server it would be great.

Yes, I started a new fresh console (I believe) I hit ctrl +d and then I ran the code again. I also tried going to the consolo management page and close it there.

One thing to check if you get a 403 error is whether it's coming from our systems or from the site you're trying to connect to. 403 just means "access denied", so our proxy returns it if an account is not on the allowlist, but other sites might return it if (for example) they're blocking your access due to invalid credentials, or if they block requests with particular IP addresses, or something like that. If you look at the contents of the response, you should be able to tell which case it is.

Ohh ok, I will have a look. Thanks!