I have below python code, but it isnt working.
PYTHON CODE
import upstox_client
import requests
from time import sleep
import xlwings as xw
global api_key, secret_key, r_url, topt_key, mobile_no, pin
wb = xw.Book(‘TradeToolsUpstox.xlsx’)
crd = wb.sheets(“Cread”)
api_key = crd [‘B1’].value
secret_key = crd [‘B2’].value
r_url = crd [‘B3’].value
topt_key = crd [‘B4’].value
mobile_no = crd [‘B5’].value
pin = crd [‘B6’].value
auth_url = f’https://api.upstox.com/v2/login/authorization/dialog?response_type=code&client_id={api_key}&redirect_uri={r_url}’
#code = urlparse.parse_qs(parsed.query)[‘code’][0]
url = ‘https://api.upstox.com/v2/login/authorization/token’
code=‘’
headers = {
‘accept’: ‘application/json’,
‘Api-Version’: ‘2.0’,
‘Content-Type’: ‘application/x-www-form-urlencoded’}
payload = {
‘code’: code,
‘client_id’ : api_key,
‘client_secret’: secret_key,
‘redirect_uri’: r_url,
‘grant_type’: ‘authorization_code’}
response = requests.post(url, headers=headers, data=payload)
if response.status_code == 200:
token = response.json().get(“access_token”)
print(“Access Token:”, token)
jsr = response.json()
with open ('accessToken.txt','w') as file:
file.write(jsr['access_token'])
print(f"Access Token : {jar['access_token']}")
else:
print(“Failed to get token:”, response.status_code, response.text)
================================================
ERROR BELOW:
Failed to get token: 400 {“status”:“error”,“errors”:[{“errorCode”:“UDAPI10000”,“message”:“This request is not supported by Upstox API”,“propertyPath”:null,“invalidValue”:null,“error_code”:“UDAPI10000”,“property_path”:null,“invalid_value”:null}]}