Max retries exceeded with url: | SSLError: HTTPSConnectionPool

grthilak
Hi,
I am getting the below error quite frequently. Last time when i got it, tries were like not more than 4 to 5 times. Kindly help.

SSLError: HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /instruments/NFO/BANKNIFTY18MAYFUT?api_key=XXX&access_token=XXX(Caused by SSLError(SSLError("bad handshake: SysCallError(-1, 'Unexpected EOF')",),))
  • sujith
    Can you provide the exact error message and status code from the API?
  • grthilak
    SysCallError Traceback (most recent call last)
    ~\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
    440 try:
    --> 441 cnx.do_handshake()
    442 except OpenSSL.SSL.WantReadError:

    ~\Anaconda3\lib\site-packages\OpenSSL\SSL.py in do_handshake(self)
    1715 result = _lib.SSL_do_handshake(self._ssl)
    -> 1716 self._raise_ssl_error(self._ssl, result)
    1717

    ~\Anaconda3\lib\site-packages\OpenSSL\SSL.py in _raise_ssl_error(self, ssl, result)
    1448 raise SysCallError(errno, errorcode.get(errno))
    -> 1449 raise SysCallError(-1, "Unexpected EOF")
    1450 else:

    SysCallError: (-1, 'Unexpected EOF')

    During handling of the above exception, another exception occurred:

    SSLError Traceback (most recent call last)
    ~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    600 body=body, headers=headers,
    --> 601 chunked=chunked)
    602

    ~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    345 try:
    --> 346 self._validate_conn(conn)
    347 except (SocketTimeout, BaseSSLError) as e:

    ~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in _validate_conn(self, conn)
    849 if not getattr(conn, 'sock', None): # AppEngine might not have `.sock`
    --> 850 conn.connect()
    851

    ~\Anaconda3\lib\site-packages\urllib3\connection.py in connect(self)
    325 server_hostname=hostname,
    --> 326 ssl_context=context)
    327

    ~\Anaconda3\lib\site-packages\urllib3\util\ssl_.py in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir)
    328 if HAS_SNI: # Platform-specific: OpenSSL with enabled SNI
    --> 329 return context.wrap_socket(sock, server_hostname=server_hostname)
    330

    ~\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
    447 except OpenSSL.SSL.Error as e:
    --> 448 raise ssl.SSLError('bad handshake: %r' % e)
    449 break

    SSLError: ("bad handshake: SysCallError(-1, 'Unexpected EOF')",)

    During handling of the above exception, another exception occurred:

    MaxRetryError Traceback (most recent call last)
    ~\Anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    439 retries=self.max_retries,
    --> 440 timeout=timeout
    441 )

    ~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    638 retries = retries.increment(method, url, error=e, _pool=self,
    --> 639 _stacktrace=sys.exc_info()[2])
    640 retries.sleep()

    ~\Anaconda3\lib\site-packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
    387 if new_retry.is_exhausted():
    --> 388 raise MaxRetryError(_pool, url, error or ResponseError(cause))
    389

    MaxRetryError: HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /instruments/NFO/BANKNIFTY18MAYFUT?api_key=XXXX&access_token=XXXX (Caused by SSLError(SSLError("bad handshake: SysCallError(-1, 'Unexpected EOF')",),))

    During handling of the above exception, another exception occurred:

    SSLError Traceback (most recent call last)
    in ()
    130 # """
    131
    --> 132 vix_fibonacci()
    133 # thread_1 = Thread(target=vix_fibonacci, args=[])
    134 # #thread_2 = Thread(target=open_high_low, args=[])

    in vix_fibonacci()
    104 if long and stock == 'stock_long':
    105 url = base_url.format(STOCKS[stock], access_token)
    --> 106 response = requests.get(url).json()
    107 print ("Current price of long - {} : {} < {}".format(STOCKS['stock_long'],
    108 response['data']['last_price'],

    ~\Anaconda3\lib\site-packages\requests\api.py in get(url, params, **kwargs)
    70
    71 kwargs.setdefault('allow_redirects', True)
    ---> 72 return request('get', url, params=params, **kwargs)
    73
    74

    ~\Anaconda3\lib\site-packages\requests\api.py in request(method, url, **kwargs)
    56 # cases, and look like a memory leak in others.
    57 with sessions.Session() as session:
    ---> 58 return session.request(method=method, url=url, **kwargs)
    59
    60

    ~\Anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    506 }
    507 send_kwargs.update(settings)
    --> 508 resp = self.send(prep, **send_kwargs)
    509
    510 return resp

    ~\Anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
    616
    617 # Send the request
    --> 618 r = adapter.send(request, **kwargs)
    619
    620 # Total elapsed time of the request (approximately)

    ~\Anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    504 if isinstance(e.reason, _SSLError):
    505 # This branch is for urllib3 v1.22 and later.
    --> 506 raise SSLError(e, request=request)
    507
    508 raise ConnectionError(e, request=request)

    SSLError: HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /instruments/NFO/BANKNIFTY18MAYFUT?api_key=XXXX&access_token=XXXX (Caused by SSLError(SSLError("bad handshake: SysCallError(-1, 'Unexpected EOF')",),))
  • krmadala
    Hi sujith,
    I am also getting same issue .can you provide a way to resolve the issue. while executing second line

    kite = KiteConnect(api_key="xxxxxxx")
    data = kite.generate_session("xxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxx")
  • sujith
    You can refer to the similar thread here.
  • rajagopalsri
    hi,

    I am getting the same error today;

    "
    HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /session/token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1076)'))) "

    i am using python API -
    kite = KiteConnect(api_key=key_secret[0])
    data = kite.generate_session(request_token, api_secret=key_secret[1])

    how to resolve?
  • sujith
    You seem to be using a self-signed SSL certificate, you need to get the certificate from a recognized authority.
Sign In or Register to comment.