Curl Works but not Request - Need Help

pracas
The CURL example given for getting the authentication token works however the following python code using requests... returns a 400 error.. what could be wrong? Any suggestions? I've checked the CURL command with the values of the variables used here and it works well.


url = 'https://api.kite.trade/session/token'
myheaders = {'X-Kite-Version': '3'}
data = {"api_key": api_key, "request_token": request_token, "checksum": sha_signature}
res = requests.post(url, json=data, headers=myheaders)
print (res.status_code)
print (res.raise_for_status())


ERROR
HTTPError: 400 Client Error: Bad Request for url: https://api.kite.trade/session/token
  • zartimus
    zartimus edited February 2018
    @pracas Please check this.
    Try using the pykiteconnect client library.

    ^ Points on debugging your issue
    Bad request clearly means the request you are sending is some or the other way wrong. Try printing res.request.__dict__
    * Change json param of post call to data as the former sets the content type as json.
    * SHA signature might be wrong.
Sign In or Register to comment.