Error during authentication token generation

i have the following code after generating the response code.

import requests
url=‘https://api-v2.upstox.com/login/authorization/token
data ={
‘code’: ‘FT8Z4C’,
‘client_id’:‘xyz’,
‘client_secret’: '‘xyl’,
‘redirect_url’: ‘https://localhost:6000’,
‘grant_type’: ‘authorization_code’
}

response = requests.post(url, headers=headers, data=data)
jsonresponse = response.json()
{‘status’: ‘error’,
‘errors’: [{‘errorCode’: ‘UDAPI10000’,
‘message’: ‘This request is not supported by Upstox API’,
‘propertyPath’: None,
‘invalidValue’: None,
‘error_code’: ‘UDAPI10000’,
‘property_path’: None,
‘invalid_value’: {‘status’: ‘error’,
‘errors’: [{‘errorCode’: ‘UDAPI10000’,
‘message’: ‘This request is not supported by Upstox API’,
‘propertyPath’: None,
‘invalidValue’: None,
‘error_code’: ‘UDAPI10000’,
‘property_path’: None,
‘invalid_value’: None}]}
{‘status’: ‘error’,
‘errors’: [{‘errorCode’: ‘UDAPI10000’,
‘message’: ‘This request is not supported by Upstox API’,
‘propertyPath’: None,
‘invalidValue’: None,
‘error_code’: ‘UDAPI10000’,
‘property_path’: None,
‘invalid_value’: None}]}
}]}

kindly guide

upstox returns

This request is not supported by Upstox API - Indicates that the API call made was invalid or unrecognized. This could be due to improperly formatted URL, invalid headers values or the inclusion of unexpected characters in the URL.It’s recommended to review your headers once. Here

Below is the correct code for generating the access token, which has been thoroughly tested and verified as functional.

import requests

auth_code = 'xxxxx'
client_id = 'xxxxx'
client_secret = 'xxxxx'
redirect_uri = 'xxxxx'

url = 'https://api.upstox.com/v2/login/authorization/token'

headers = {
    'accept': 'application/json',
    'Api-Version': '2.0',
    'Content-Type': 'application/x-www-form-urlencoded'
}
data = {
    'code': auth_code,
    'client_id': client_id,
    'client_secret': client_secret,
    'redirect_uri': redirect_uri,
    'grant_type': 'authorization_code'
}

response = requests.post(url, headers=headers, data=data)

I noticed that you’re still using the previous URL. As mentioned in the changelog at Changelog | Upstox Developer API. It’s advised to switch the API base URL to https://api.upstox.com/v2/ from the existing https://api-v2.upstox.com. It’s important to mention that the error you are facing is not related to the url change.