Browser returns 200 OK but requests and urllib.request.Request returns 403

17 Views Asked by At

I'm trying to 'get' some URLs, some of them return 403 but they open on the browser returning 200 OK.

headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.79 Safari/537.36'}
session = requests.Session()
session. headers.update(headers)

response= session.get('<url>'.strip(), timeout=15, allow_redirects=True)
print(response.status_code)

This returns 403. I've seen a lot of posts here suggesting adding headers and using session like I've used here, but that didn't seem to solve the issue. Any help regarding this would be appreciated. Thank you!

0

There are 0 best solutions below