403 Error

Sort:
Masterclass_Insanity

Hey everyone, I am new to the world of coding and am going to start a major in data analytics soon. I did a little IBM course to get a feel for the subject, but the projects were very much engineered, and didn't feel like I was actually doing anything. So, I decided that on my first 'real world' project, I would make something that can grab the API for my stats so I can make a regression plot for my Elo or just some neat graphs or something. It didn't take long for me to get my first error, and after consulting with the almighty chat-gpt, I have been led here to try and solve my problem. The error I am getting is a 403 error which seems to indicate that my authentication is being blocked. Any help would be appreciated, and is this project something I can even do?

GM_Salzi

you have to send your contact information in the header of the request. The api was overloaded for some time so the developers added the need of authentification to make sure one user does not send a million requests per day. If you are using python your code could look like this:

response = requests.get(url, headers = {'User-Agent': 'username: myaccount, email: my@emaill'})

data = response.json()

Masterclass_Insanity

Seems to have done the trick!

Takin_These

just what i was looking for. can this information be included into the readme? i dont think its currently in there

I was wondering why i was getting 403 in python but not in browser

Takin_These

Ok i actually just tested this out in Spyder now and im still getting the 403

my code:

headers = {'User-Agent':'username: Takin_These, email: myemail@gmail.com'}

URL = 'https://api.chess.com/pub/player/hikaru/games/archives'

data = requests.get(URL, headers)

anyone got ideas?

i can still access the same API end points in chrome

Takin_These

it was a syntax error

headers = {'User-Agent':'username: Takin_These, email: myemail@gmail.com'}

URL = 'https://api.chess.com/pub/player/hikaru/games/archives'

data = requests.get(URL, header=headers)

this works