import requests
def create_student(token, data):
headers = {"Authorization": f"Bearer {token}"}
try:
response = requests.post(
"https://api.chessplay.io/api/v1/students/",
headers=headers,
json=data
)
response.raise_for_status()
return response.json()
except requests.exceptions.HTTPError as e:
if e.response.status_code == 400:
print(f"Validation error: {e.response.json()}")
elif e.response.status_code == 401:
print("Authentication failed. Login again.")
elif e.response.status_code == 403:
print("Need admin permissions.")
else:
print(f"Error: {e.response.status_code}")
return None