kaysuez
kaysuez

Reputation: 97

Requests in python returning 403

I have a simple requests code that pulls from ESPN's RSS feed.

import requests
requests.get('https://www.espn.com/espn/rss/news')

it was working a few weeks ago, and now i'm getting a 403 error. Definitely not a threshold limit, as this is my first time running it in weeks. I read 403 could mean forbidden and you need a login, but if you simply input https://www.espn.com/espn/rss/news into your web browser all the relevant info comes up. Any idea why requests can't grab it suddenly?

Upvotes: -1

Views: 1431

Answers (1)

X-_-FARZA_ D-_-X
X-_-FARZA_ D-_-X

Reputation: 544

it's because of your User-Agent

this is how you can alter user agent data in requests

import requests

res = requests.get('https://www.espn.com/espn/rss/news', headers={
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
})
print(res)

now it returns status code 200

Upvotes: 1

Related Questions