Yeah, when using Cloudflare Workers (or any hosted setup), Chess.com’s API will block requests without proper headers — especially the User-Agent. They expect devs to identify themselves clearly.
Here’s how I do it in Python, and it works fine with the /stats endpoint:
import requests
def get_player_stats(username):
url = f"https://api.chess.com/pub/player/{username}/stats"
headers = {
"User-Agent": "ChessStatsWorker/1.0 (contact: senti3ntb3ing@example.com; project: https://github.com/senti3ntb3ing/chess-stats-worker)",
"Accept": "application/json",
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()
elif response.status_code == 403:
print("403 Forbidden – usually means your headers are missing or you’ve been blocked.")
elif response.status_code == 404:
print("404 Not Found – the username might not exist or the endpoint is wrong.")
elif response.status_code == 429:
print("429 Too Many Requests – you're hitting the rate limit, try slowing down.")
else:
print(f"Request failed with status: {response.status_code}")
print(response.text)
# Example
print(get_player_stats("Hikaru"))
🔑 Why the User-Agent matters:Chess.com recommends something like:YourAppName/1.0 (contact: your@email.com; project: URL)
This tells their team who to contact if something goes wrong or if your app misbehaves.
If you leave out the User-Agent, or use the default from Python or JS, your request is much more likely to get blocked.
Let me know if you need a JS/Cloudflare Worker version — happy to help.
AlAlper – Founder, ChessDev Hub
(Helping coders for less than 1 week on Chess.com) 😅
Trying to pull the stats of a user via Cloudflare worker, using the `api.chess.com/pub/player/stats` endpoint is returning an html response saying that the request was blocked. Are there specific headers I need to be including with the request to get around this? Haven't had this issue with my bot before, but it was hosted on a separate service before. Any help would be much appreciated.