ConnectionRefusedError: [Errno 61] Connection refused while connecting thru autlogin python code.

sumeet1982
Hello Team,
Trying to execute below using
response1 = http_session.post(url='https://kite.zerodha.com/api/twofa', data={'user_id':user_id, 'request_id':resp_dict["data"]["request_id"], 'twofa_value': twofa_value, 'twofa_type': resp_dict["data"]["twofa_type"]})
url = url + "&skip_session=true"
response = http_session.get(url=url, allow_redirects = True).url
request_token = parse_qs(urlparse(response).query)['request_token'][0]

already imported request .
import requests, json, pyotp, urllib3
from kiteconnect import KiteConnect
from urllib.parse import urlparse
from urllib.parse import parse_qs

Redirect URL used : http://127.0.0.1:5010/login

Error:
create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 61] Connection refused

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=5010): Max retries exceeded with url: /login?status=success&request_token=N0GjGXhjpVdoFLfy4831Hty3VXQYwPW5&action=login&type=login (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 61] Connection refused'))
  • sumeet1982
    Please help
  • tonystark
    You seem to be using APIs that are not part of the KiteConnect. Bear in mind that automating authentication is against exchange regulations and using unofficial APIs will lead to unforeseen disruptions.

    Please follow the method to authenticate as described here: https://kite.trade/docs/connect/v3/user/#login-flow
  • sumeet1982
    sumeet1982 edited January 5
    I am trying to automate the login process where userid and password can be entered by code only. I am using below api is this not correct ?
    'https://kite.trade/connect/login?v=3&api_key='

    def login():
    http_session = requests.Session()
    url = http_session.get(url='https://kite.trade/connect/login?v=3&api_key='+api_key).url

    response = http_session.post(url='https://kite.zerodha.com/api/login', data={'user_id':user_id, 'password':user_password})
    status = response.status_code
    resp_dict = json.loads(response.content)
    print(resp_dict)
    totp = pyotp.TOTP(totp_key)
    twofa_value = totp.now()
    response1 = http_session.post(url='https://kite.zerodha.com/api/twofa', data={'user_id':user_id, 'request_id':resp_dict["data"]["request_id"], 'twofa_value': twofa_value, 'twofa_type': resp_dict["data"]["twofa_type"]})
    url = url + "&skip_session=true"
    response = http_session.get(url=url, allow_redirects = True).url
    request_token = parse_qs(urlparse(response).query)['request_token'][0]
    print(request_token)
    kite = KiteConnect(api_key=api_key)
    data = kite.generate_session(request_token, api_secret=api_secret)
    kite.set_access_token(data["access_token"])


  • tonystark
    It is mandatory by the exchange that a trader has to log in manually at least once in a day. We don't recommend automating the login.
Sign In or Register to comment.