-3

Python error when using request get

Hello guys i have this in my code

from bs4 import BeautifulSoup
r = requests.get(url)

And I'm gettin this

<Response [403]>

Whats could be the solution

The url is 'https://www3.animeflv.net/anime/sailor-moon'

btw the title is weird because i dont know why stack overflow dont allow me the way i want to put it :(

1 Answers1

1

For your specific case you can overcome that by faking your User-Agent in request headers.

import requests

url = 'https://www3.animeflv.net/anime/sailor-moon'
headers = {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'}

res = requests.get(url, headers=headers)

print(res.status_code)

<Response [200]>

Some websites try to block requests made with python requests library, by default when you make a request from python script your User-Agent is something like python3/requests but if you fake it with manipulating headers you can easily bypass that. Take a look at this library https://pypi.org/project/fake-useragent/ for generating fake User-Agent strings.

djyra
  • 11
  • 3
  • Thanks for the help, still the status code, print 403 – Fernando Benavides May 08 '21 at 18:50
  • Try using free proxies, they might have blocked your IP, here is how to us them with requests https://stackoverflow.com/questions/8287628/proxies-with-python-requests-module and here you can find list of some free proxies https://www.proxyscrape.com/free-proxy-list note that free proxies don't work right away because they might have a lot of traffic on them, try repeating request couple of times or make a list of proxies and try with different ones. – djyra May 08 '21 at 18:54