Getting KiteNoNetworkException error

utlsingh
utlsingh edited December 2017 in Java client
Hey all ,

I am getting this error :
Exception in thread "main" com.rainmatter.kitehttp.exceptions.KiteNoNetworkException
at com.rainmatter.kitehttp.KiteRequest.postRequest(KiteRequest.java:57)
at com.rainmatter.kiteconnect.KiteConnect.requestAccessToken(KiteConnect.java:176)
at FinalDestination.main(FinalDestination.java:36)
My code is
public class FinalDestination {

public static void main(String []args) throws JSONException, KiteException {

KiteConnect kiteSdk = new KiteConnect("api_key");
kiteSdk.setUserId("user_id");

//String url = kiteSdk.getLoginUrl();
//System.out.println(url);
// Get accessToken as follows,
UserModel userModel = kiteSdk.requestAccessToken("request_token", "secret_key");

kiteSdk.setAccessToken(userModel.accessToken);
kiteSdk.setPublicToken(userModel.publicToken);

Margins margins = kiteSdk.getMargins("equity");
System.out.println(margins.available.cash);

}
}
I have got the request token but facing problem while getting access token .

Please help , i will be very thankful to you guys . Thanks in advance .
  • utlsingh
    I hope api key , secret key and request token does not expire as i got it one day before .
  • utlsingh
    I found something more on this . Its a connection error . I can i resolve it ?
  • sujith
    Hi,
    A request token is valid for a couple of minutes and can be used only once.
    You need to wrap your code inside try block and print kiteException.message which will give us more info.
  • sujith
    Once you get access token it is valid for one day and don't requestAccessToken for every run.
  • sujith
    Once you get access token re-use it in subsequent runs.
  • utlsingh
    utlsingh edited December 2017
    Hey @sujith

    I am getting connection error again . I just updated the request token also because you said it might have expired .
    Do i have to update the api key and api secret also ? .
    Here is my code :
     class FinalDestination {

    public static void main(String []args) {

    KiteConnect kiteSdk = new KiteConnect("api_key");
    kiteSdk.setUserId("user_id");

    //String url = kiteSdk.getLoginUrl();
    //System.out.println(url);
    // Get accessToken as follows,
    UserModel userModel;
    try {
    userModel = kiteSdk.requestAccessToken("request_token", "api_secret");

    kiteSdk.setAccessToken(userModel.accessToken);
    kiteSdk.setPublicToken(userModel.publicToken);
    } catch (KiteException e) {
    // TODO Auto-generated catch block
    System.out.println(e.message);
    }

    Margins margins;
    try {
    margins = kiteSdk.getMargins("equity");
    System.out.println(margins.available.cash);
    } catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (KiteException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
    }
  • sujith
    The api_key and api_secret remain constant for an App. You don't have to change that.
    I am not sure where you are going wrong.
    You can check out webinar for login flow.
  • utlsingh

    Is there any support team with whom i can talk ?
  • sujith
    Hi,
    We don't provide phone support for Kite Connect.
    You can follow the exact procedure as shown in the webinar and private message me that. I will check and get back to you.
Sign In or Register to comment.