Problem in getting Access Token

On requesting access token, the api returns:
{“status”:“Bad Request”,“result”:{“errors”:[{“message”:“Client id not received with the request. Check API documentation and content type of your request”,“code”:“Bad Request”}]}}

I am using the following code to request access token:
headers = {‘content-Type’: ‘application/json’,}
data = {‘grant_type’: ‘authorization_code’, ‘code’: authorization_code, ‘client_id’: client_id, ‘client_secret’: client_secret, ‘redirect_uri’: callback_uri}
access_token_response = requests.post(‘https://api.codechef.com/oauth/token’, headers=headers, data=data)

with appropriate values in place of authorization_code, client_id and client_secret, and callback_uri = “http://127.0.0.1:8000/

1 Like

The last line of your code should be:

access_token_response = requests.post(‘https://api.codechef.com/oauth/token’, data=json.dumps(data), headers=headers)

data is a Python object and you must convert it into a JSON formatted string using json.dumps()

//