Kite APIs Proxy Server Option

srn11
Hi

I faced proxy server issue and searched the forum and found resolution in below thread.

https://kite.trade/forum/discussion/631/trouble-logging-in-behind-a-proxy-server

My KiteConnect version is 3.4 and i am able to execute kite=KiteConnect(api_key=apikey, proxies=proxy) and get the login information by routing through proxy

After login when i use kite.historical API i get back the gateway Connection Exception error that i had initially got when i faced the proxy issue at login. kite.historical API does not have proxy variable to pass value.

I want to know how to resolve this problem of accessing historical data when a proxy comes into the picture even though i am able to successfully login. The exact same code works fine in non-proxy environment.

Errors:
Traceback (most recent call last):
execfile(filename, namespace)
exec(compile(scripttext, filename, 'exec'), glob, loc)
kite.historical(inst, from_date, to_date, interval)
\kiteconnect\__init__.py", line 415, in historical "interval": interval})
\kiteconnect\__init__.py", line 455, in _get return self._request(route, "GET", params)
\kiteconnect\__init__.py", line 510, in _request
raise ex.ClientNetworkException("Gateway connection error", code=503)

ClientNetworkException: Gateway connection error

-SR
Tagged:
  • srn11
    I tried debugging, the 7th line in the error output traces to a request definition which does have proxies but in historial API (unlike Connect API) does not have proxies as a parameter

    Tagging few folks @vivek @Nikhil.A @Kailash

    -SR
  • sujith
    Hi,
    Proxy that is being set while initialising KiteConnect is used by all requests. Checkout https://github.com/rainmattertech/pykiteconnect/blob/master/kiteconnect/__init__.py
  • srn11
    Hi Sujith

    That was my assumption as well but it did not work. I was able to set the proxy at login and i got the key and was able to get Kite API login output. After that historial API is erroring out with ClientNetworkException: Gateway connection error

    -SR
  • srn11
    @sujith

    I am still facing this problem. Able to successfully login but beyond that the historical Function errors out with Gateway connection error. The error trace is mentioned in post#1. Can you please look into it or let me know what more data you need to help in debug.

    -SR
  • srn11
    Trying to debug the issue, through proxy i am able to access KiteConnect function but kite.historical does not work.

    print(KiteConnect(api_key=apikey))


    print(kite.historical(StockInstToken, FromDate, ToDate, interval)
    Traceback (most recent call last):
    execfile(filename, namespace)
    exec(compile(scripttext, filename, 'exec'), glob, loc)
    kite.historical(inst, from_date, to_date, interval)
    \kiteconnect\__init__.py", line 415, in historical "interval": interval})
    \kiteconnect\__init__.py", line 455, in _get return self._request(route, "GET", params)
    \kiteconnect\__init__.py", line 510, in _request
    raise ex.ClientNetworkException("Gateway connection error", code=503)

    ClientNetworkException: Gateway connection erro

    As mentioned earlier without any changes the above code works when there is no proxy involved.

    @sujith @vivek @Kailash

    -SR
  • sujith
    Can you try curl to historical data API with proxy and check what is the error?
  • Vivek
    Vivek edited November 2016
    @srn11 As sujith said you can directly curl historical api with your proxy setting and see whats the error you are getting.
    https://api.kite.trade/instruments/historical/738561/minute?access_token=your_access_token&api_key=your_api_key&from=2016-11-28&to=2016-11-28
    Here is how you can pass proxy settings to curl.
  • sr11
    The issue was that i was evaluating proxy and non-proxy environment based on kite.connect API's output. I was expecting kite.connect (without proxy variable) to give an exception in a proxy environment. However kite.connect never erorred out and it was historical API that was catching the proxy & non-proxy environment. Now i have added a step before kite,connect to detect proxy and connect by passing proxy variable if required.

    A suggestion for the forum web-layout, if you can add post# in each message, it will be easier to refer to earlier posts.

    Thanks Sujith, Vivek. This thread can be closed.

    -SR
This discussion has been closed.