Error 403 in member profile

Sort:
Avatar of Martin_Stahl
Tricky_Dicky wrote:

Yes, after the previous time the user agent functionality changed from optional to compulsory and it was only published because people complained that there had been no advanced notice.

It was published as soon as we were made aware of the change being made by the staff member that made the change.

The code change was made on June 20th and the Announcement was posted the same day.

Avatar of Tricky_Dicky

Martin_Stahl

Jun 20, 2023

Just found out you have to have a descriptive user agent with username or email of the owner of the script which is using PubAPI now. It's being required at this point.

Tricky_Dicky

That's interesting Martin, and a good thing IMO. When did that get announced publically.

Martin_Stahl

Jun 20, 2023

It wasn't announced publicly. I just found out about it earlier.

Tricky_Dicky

Not brilliant communication then for an information site. 10 out of 10 to the devs for their progress. -several million for the information provided to users.

MasterMatthew52

Jun 20, 2023

Is this something very recent? Like in the past few days.

N8Sun

Jun 20, 2023

Suddenly changed the API endpoint call but no announcements, no notice, no proper guidelines to use new API endpoint call. I am not sure is it the proper way to change an ongoing things.

Martin_Stahl

Jun 20, 2023

It's always been recommended to include contact details in the user agent string. It's just being enforced now.

Tricky_Dicky

Firstly I agree with the revised policy. It's better for the site and better for the users. The BIG issue here is the lack of transparency. The API specification does not state that it's a requirement. "In some cases, if we detect abnormal or suspicious activity, we may block your application entirely. If you supply a recognizable user-agent that contains contact information, then if we must block you application we will attempt to contact you to correct the problem."

Martin_Stahl

Jun 20, 2023

I'm asking if an announcement can be posted, so hopefully one will soon so it isn't just in notes

Avatar of Martin_Stahl

Yes, it all happened on the 20th of June.

Avatar of Tricky_Dicky

OK Martin. I concede. Chess.com are brilliant at communicating changes to the users.

Avatar of Martin_Stahl

Would it have nice for the change notification to happen before it went live? Yes. In that particular instance, I'm not aware what drove the change and it may also have been a more emergent issue that didn't lend itself to advance notification.

As it is, the announcement was published within 6 hours of the change happening and 4 hours after I initially saw posts about it.

Avatar of stephen_33
Martin_Stahl wrote:
Tricky_Dicky wrote:

Yes, after the previous time the user agent functionality changed from optional to compulsory and it was only published because people complained that there had been no advanced notice.

It was published as soon as we were made aware of the change being made by the staff member that made the change.

The code change was made on June 20th and the Announcement was posted the same day.

Recent events have highlighted that those with 'control of the site' fail to communicate important changes to you and jdcannon as much as to the wider membership. At least that's how I see things.

On a properly managed site, shouldn't you be informed about such changes in advance so that (a) you know what's actually about to be changed and (b) you can takes steps (if appropriate) to advise or warn members like ourselves about this?

Avatar of Martin_Stahl

The most recent change was late in the evening on a Saturday. The previous one was done very early in the morning.

The most recent one was essentially an emergency change, done to solve an issue. Based on the earliness of the previous one, I'm guessing it was as well

Avatar of LRositto
AfraidToShootStrangers wrote:

Hi, i'm a new chess player and an amateur programmer. I have wrote a very simple script in python to request stats info on my account and game history.

Since yesterday i'm getting error 403, same as you guys. I only run sequential requests as demanded in the policy.

Can you explain better to me the user-agent thing. It is a parameters?

Should i use in my request to chess.com api the parameter user-aget?

Is this something like that correct?

[CODE]

r = requests.get("https://api.chess.com/pub/player/playername/stats",

params = {'User-Agent': 'mycontact@gmail.com'})

[/CODE]

Thank you.

The user agent seems fine, do make sure to pass it to the requests.get line as a headers parameter.
r = requests.get("https://api.chess.com/pub/player/playername/stats", headers=params)

Avatar of twellener

Can anyone explain to me why this is incorrect? I'm still getting the 403 error for Python

response = requests.get('https://api.chess.com/pub/player/hikaru/stats', headers = {'User-Agent':'hello@gmail.com'})

response.raise_for_status()

archives = response.json()['archives']

print(archives)

Avatar of sjbfan
twellener wrote:

Can anyone explain to me why this is incorrect? I'm still getting the 403 error for Python

response = requests.get('https://api.chess.com/pub/player/hikaru/stats', headers = {'User-Agent':'hello@gmail.com'})

response.raise_for_status()

archives = response.json()['archives']

print(archives)

it's better practice to use variables like this to avoid errors and so you can troubleshoot better. The error I found with your problem though is that there is no Archive in the stats endpoint.

url = "https://api.chess.com/pub/player/hikaru/stats"

headers = {
'User-Agent': 'hello@bye.com'
}

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

data = response.json()

print(data)

Avatar of twellener

thanks for the reply. i'm still getting an error 403. Do you see anything wrong with this code? Any help is greatly appreciated.

import discord
import requests
from discord.ext import commands

PREFIX = '!'
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=PREFIX, intents=intents)

# Define the header with your email as the User-Agent
HEADERS = {'User-Agent': 'test@gmail.com'}

@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))

@bot.event
async def on_message(message):
if message.content == "hello":
await message.channel.send('hello')

await bot.process_commands(message) # This line allows commands to be processed.

@bot.command()
async def chessstats(ctx, username: str):
try:
# Fetch the stats of the user from the Chess.com API using the defined headers
response = requests.get(f'https://api.chess.com/pub/player/{username}/stats', headers=HEADERS)
response.raise_for_status() # Check the HTTP status

data = response.json()

# Here, I'm assuming you'd want to print stats for chess blitz. You can adjust this for other game types.
blitz_stats = data.get('chess_blitz', {})

# Getting record (win, loss, draw)
record = blitz_stats.get('record', {})
wins = record.get('win', 0)
losses = record.get('loss', 0)
draws = record.get('draw', 0)

# Send the results to Discord
await ctx.send(f"Stats for {username}:\nWins: {wins}\nLosses: {losses}\nDraws: {draws}")

except requests.RequestException as e:
await ctx.send(f"Error fetching data for {username}: {str(e)}")

Avatar of sjbfan
twellener wrote:

thanks for the reply. i'm still getting an error 403. Do you see anything wrong with this code? Any help is greatly appreciated.

import discord
import requests
from discord.ext import commands

PREFIX = '!'
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=PREFIX, intents=intents)

# Define the header with your email as the User-Agent
HEADERS = {'User-Agent': 'test@gmail.com'}

@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))

@bot.event
async def on_message(message):
if message.content == "hello":
await message.channel.send('hello')

await bot.process_commands(message) # This line allows commands to be processed.

@bot.command()
async def chessstats(ctx, username: str):
try:
# Fetch the stats of the user from the Chess.com API using the defined headers
response = requests.get(f'https://api.chess.com/pub/player/{username}/stats', headers=HEADERS)
response.raise_for_status() # Check the HTTP status

data = response.json()

# Here, I'm assuming you'd want to print stats for chess blitz. You can adjust this for other game types.
blitz_stats = data.get('chess_blitz', {})

# Getting record (win, loss, draw)
record = blitz_stats.get('record', {})
wins = record.get('win', 0)
losses = record.get('loss', 0)
draws = record.get('draw', 0)

# Send the results to Discord
await ctx.send(f"Stats for {username}:\nWins: {wins}\nLosses: {losses}\nDraws: {draws}")

except requests.RequestException as e:
await ctx.send(f"Error fetching data for {username}: {str(e)}")

I can't scan all your code but I just tested a request using this snippet from your code and it works fine:

HEADERS = {'User-Agent': 'test@gmail.com'}
response = requests.get(f'https://api.chess.com/pub/player/hikaru/stats', headers=HEADERS)
response.raise_for_status() # Check the HTTP status

data = response.json()

# Here, I'm assuming you'd want to print stats for chess blitz. You can adjust this for other game types.
blitz_stats = data.get('chess_blitz', {})

print(blitz_stats)

Avatar of stephen_33
twellener wrote:

Can anyone explain to me why this is incorrect? I'm still getting the 403 error for Python

response = requests.get('https://api.chess.com/pub/player/hikaru/stats', headers = {'User-Agent':'hello@gmail.com'})

response.raise_for_status()

archives = response.json()['archives']

print(archives)

Are you still getting a '403' response?

It gives me a 200 status which is what I'd expect if everything's working normally.