Trouble logging in behind a proxy server

dummydost
dummydost edited October 2016 in Python client
So, I am behind an authenticated proxy server.
When I run the following python script,


#! /usr/bin/python3.5

from kiteconnect import KiteConnect

kite = KiteConnect(api_key="xxx")

try:
user = kite.request_access_token(request_token="yyy",secret="zzz")
kite.set_access_token(user["access_token"])
except Exception as e:
print("Authentication failed", str(e))
raise

print(user["user_id"], "has logged in")

print(kite.positions())

order_id = kite.order_place(
tradingsymbol="INFY",
exchange="NSE",
quantity=1,
transaction_type="BUY",
order_type="MARKET"
)


I get errors. The full stacktrace is:


Authentication failed Gateway connection error
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 555, in urlopen
self._prepare_proxy(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 753, in _prepare_proxy
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 230, in connect
self._tunnel()
File "/usr/lib/python3.5/http/client.py", line 832, in _tunnel
message.strip()))
OSError: Tunnel connection failed: 407 Proxy Authentication Required

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 376, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 610, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 273, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /session/token (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required',)))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/kiteconnect/__init__.py", line 494, in _request
timeout=self._timeout)
File "/usr/lib/python3/dist-packages/requests/api.py", line 53, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 437, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /session/token (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required',)))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "./kite.py", line 11, in <module>
user = kite.request_access_token(request_token="v5vy474hp416qbhw32zhebvkrth2er81",secret="pipnm9z3lnlvssp2a3z8oxndzde0e87z")
File "/usr/local/lib/python3.5/dist-packages/kiteconnect/__init__.py", line 215, in request_access_token
"checksum": checksum
File "/usr/local/lib/python3.5/dist-packages/kiteconnect/__init__.py", line 446, in _post
return self._request(route, "POST", params)
File "/usr/local/lib/python3.5/dist-packages/kiteconnect/__init__.py", line 496, in _request
raise ex.ClientNetworkException("Gateway connection error", code=503)
kiteconnect.exceptions.ClientNetworkException: Gateway connection error


Everything else is correct, api key, secret key, request token etc. It's just that I don't know how to force use of proxy with official python client.How to make this script (official python client) to use proxy while connecting to the Kite Connect server?

Thanks!!
This discussion has been closed.