Traceback (most recent call last): File "C:\Program Files\Python38\lib\site-packages\urllib3\contrib\pyopenssl.py", line 485, in wrap_socket cnx.do_handshake() File "C:\Program Files\Python38\lib\site-packages\OpenSSL\SSL.py", line 1934, in do_handshake self._raise_ssl_error(self._ssl, result) File "C:\Program Files\Python38\lib\site-packages\OpenSSL\SSL.py", line 1646, in _raise_ssl_error raise WantReadError() OpenSSL.SSL.WantReadError
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 376, in _make_request self._validate_conn(conn) File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn conn.connect() File "C:\Program Files\Python38\lib\site-packages\urllib3\connection.py", line 352, in connect self.sock = ssl_wrap_socket( File "C:\Program Files\Python38\lib\site-packages\urllib3\util\ssl_.py", line 370, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "C:\Program Files\Python38\lib\site-packages\urllib3\contrib\pyopenssl.py", line 488, in wrap_socket raise timeout("select timed out") socket.timeout: select timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Program Files\Python38\lib\site-packages\requests\adapters.py", line 439, in send resp = conn.urlopen( File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 719, in urlopen retries = retries.increment( File "C:\Program Files\Python38\lib\site-packages\urllib3\util\retry.py", line 400, in increment raise six.reraise(type(error), error, _stacktrace) File "C:\Program Files\Python38\lib\site-packages\urllib3\packages\six.py", line 735, in reraise raise value File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen httplib_response = self._make_request( File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 379, in _make_request self._raise_timeout(err=e, url=url, timeout_value=conn.timeout) File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 330, in _raise_timeout raise ReadTimeoutError( urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=7)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:/Users/Vikram/PycharmProjects/vik/venv/autotrade/5SMA13Feb.py", line 48, in call_ltp = kite.ltp('NSE:EICHERMOT') File "C:\Program Files\Python38\lib\site-packages\kiteconnect-3.8.1-py3.8.egg\kiteconnect\connect.py", line 595, in ltp File "C:\Program Files\Python38\lib\site-packages\kiteconnect-3.8.1-py3.8.egg\kiteconnect\connect.py", line 817, in _get File "C:\Program Files\Python38\lib\site-packages\kiteconnect-3.8.1-py3.8.egg\kiteconnect\connect.py", line 865, in _request File "C:\Program Files\Python38\lib\site-packages\kiteconnect-3.8.1-py3.8.egg\kiteconnect\connect.py", line 854, in _request File "C:\Program Files\Python38\lib\site-packages\requests\api.py", line 60, in request return session.request(method=method, url=url, **kwargs) File "C:\Program Files\Python38\lib\site-packages\requests\sessions.py", line 533, in request resp = self.send(prep, **send_kwargs) File "C:\Program Files\Python38\lib\site-packages\requests\sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "C:\Program Files\Python38\lib\site-packages\requests\adapters.py", line 529, in send raise ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=7)
I still don't get it. i have imported and try and excepted the following still i am getting this crash after program runs smoothly for 2 hours. Why is it happening? I had ORed "MaxRetryError" and "timeout":
"""------------Code-------------------------------------------------------------------------------------""" from OpenSSL import SSL from OpenSSL.SSL import SysCallError, WantReadError from kiteconnect import KiteConnect from kiteconnect import KiteTicker from requests import ReadTimeout from urllib3.exceptions import MaxRetryError, SSLError, ReadTimeoutError, HTTPError from urllib3.util import timeout
try: call_ltp = kite.ltp(sy) except ConnectionError or TimeoutError or SSLError or SysCallError or MaxRetryError or WantReadError or timeout \ or ReadTimeoutError or ReadTimeout or SSL or HTTPError: time.sleep(1) try: call_ltp = kite.ltp(sy) except ConnectionError or TimeoutError or SSLError or SysCallError or MaxRetryError or WantReadError or \ timeout or ReadTimeoutError or ReadTimeout or SSL or HTTPError: time.sleep(1) try: call_ltp = kite.ltp(sy)
"""-----------Error-----------------------------------------------------------------------------------------------""" Traceback (most recent call last): File "C:\Program Files\Python38\lib\site-packages\urllib3\connection.py", line 156, in _new_conn conn = connection.create_connection( File "C:\Program Files\Python38\lib\site-packages\urllib3\util\connection.py", line 84, in create_connection raise err File "C:\Program Files\Python38\lib\site-packages\urllib3\util\connection.py", line 74, in create_connection sock.connect(sa) socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen httplib_response = self._make_request( File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 376, in _make_request self._validate_conn(conn) File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn conn.connect() File "C:\Program Files\Python38\lib\site-packages\urllib3\connection.py", line 300, in connect conn = self._new_conn() File "C:\Program Files\Python38\lib\site-packages\urllib3\connection.py", line 161, in _new_conn raise ConnectTimeoutError( urllib3.exceptions.ConnectTimeoutError: (, 'Connection to api.kite.trade timed out. (connect timeout=7)')
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Program Files\Python38\lib\site-packages\requests\adapters.py", line 439, in send resp = conn.urlopen( File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 719, in urlopen retries = retries.increment( File "C:\Program Files\Python38\lib\site-packages\urllib3\util\retry.py", line 436, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /quote/ltp?i=NSE%3AEICHERMOT (Caused by ConnectTimeoutError(, 'Connection to api.kite.trade timed out. (connect timeout=7)'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:/Users/Vikram/PycharmProjects/vik/venv/autotrade/5SMA13Feb.py", line 66, in call_ltp = kite.ltp(sy) File "C:\Program Files\Python38\lib\site-packages\kiteconnect-3.8.1-py3.8.egg\kiteconnect\connect.py", line 595, in ltp File "C:\Program Files\Python38\lib\site-packages\kiteconnect-3.8.1-py3.8.egg\kiteconnect\connect.py", line 817, in _get File "C:\Program Files\Python38\lib\site-packages\kiteconnect-3.8.1-py3.8.egg\kiteconnect\connect.py", line 865, in _request File "C:\Program Files\Python38\lib\site-packages\kiteconnect-3.8.1-py3.8.egg\kiteconnect\connect.py", line 854, in _request File "C:\Program Files\Python38\lib\site-packages\requests\api.py", line 60, in request return session.request(method=method, url=url, **kwargs) File "C:\Program Files\Python38\lib\site-packages\requests\sessions.py", line 533, in request resp = self.send(prep, **send_kwargs) File "C:\Program Files\Python38\lib\site-packages\requests\sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "C:\Program Files\Python38\lib\site-packages\requests\adapters.py", line 504, in send raise ConnectTimeout(e, request=request) requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /quote/ltp?i=NSE%3AEICHERMOT (Caused by ConnectTimeoutError(, 'Connection to api.kite.trade timed out. (connect timeout=7)'))
Thanks Sujith and RishiS...but still i couldn't resolve the issue. For Socket failure i guess my own internet connection might also have been responsible. As it runs and fails after some time i know that atleast i have coded correctly, so i simply made except statement without any condition(only for this calling as i'm aware that many things can go wrong with "too broad exception"), and put it on infinite loop for calling the same which eventually connects without any exceptions. By that now my program doesn't crash and reconnects when it is able to. That's what i needed. Dear vaigundamoorthy, try this (with caution)..
"""------------Code-------------------------------------------------------------------------------------"""
from OpenSSL import SSL
from OpenSSL.SSL import SysCallError, WantReadError
from kiteconnect import KiteConnect
from kiteconnect import KiteTicker
from requests import ReadTimeout
from urllib3.exceptions import MaxRetryError, SSLError, ReadTimeoutError, HTTPError
from urllib3.util import timeout
try:
call_ltp = kite.ltp(sy)
except ConnectionError or TimeoutError or SSLError or SysCallError or MaxRetryError or WantReadError or timeout \
or ReadTimeoutError or ReadTimeout or SSL or HTTPError:
time.sleep(1)
try:
call_ltp = kite.ltp(sy)
except ConnectionError or TimeoutError or SSLError or SysCallError or MaxRetryError or WantReadError or \
timeout or ReadTimeoutError or ReadTimeout or SSL or HTTPError:
time.sleep(1)
try:
call_ltp = kite.ltp(sy)
"""-----------Error-----------------------------------------------------------------------------------------------"""
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\site-packages\urllib3\connection.py", line 156, in _new_conn
conn = connection.create_connection(
File "C:\Program Files\Python38\lib\site-packages\urllib3\util\connection.py", line 84, in create_connection
raise err
File "C:\Program Files\Python38\lib\site-packages\urllib3\util\connection.py", line 74, in create_connection
sock.connect(sa)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen
httplib_response = self._make_request(
File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn
conn.connect()
File "C:\Program Files\Python38\lib\site-packages\urllib3\connection.py", line 300, in connect
conn = self._new_conn()
File "C:\Program Files\Python38\lib\site-packages\urllib3\connection.py", line 161, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (, 'Connection to api.kite.trade timed out. (connect timeout=7)')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Program Files\Python38\lib\site-packages\urllib3\connectionpool.py", line 719, in urlopen
retries = retries.increment(
File "C:\Program Files\Python38\lib\site-packages\urllib3\util\retry.py", line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /quote/ltp?i=NSE%3AEICHERMOT (Caused by ConnectTimeoutError(, 'Connection to api.kite.trade timed out. (connect timeout=7)'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Vikram/PycharmProjects/vik/venv/autotrade/5SMA13Feb.py", line 66, in
call_ltp = kite.ltp(sy)
File "C:\Program Files\Python38\lib\site-packages\kiteconnect-3.8.1-py3.8.egg\kiteconnect\connect.py", line 595, in ltp
File "C:\Program Files\Python38\lib\site-packages\kiteconnect-3.8.1-py3.8.egg\kiteconnect\connect.py", line 817, in _get
File "C:\Program Files\Python38\lib\site-packages\kiteconnect-3.8.1-py3.8.egg\kiteconnect\connect.py", line 865, in _request
File "C:\Program Files\Python38\lib\site-packages\kiteconnect-3.8.1-py3.8.egg\kiteconnect\connect.py", line 854, in _request
File "C:\Program Files\Python38\lib\site-packages\requests\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Program Files\Python38\lib\site-packages\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "C:\Program Files\Python38\lib\site-packages\requests\sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "C:\Program Files\Python38\lib\site-packages\requests\adapters.py", line 504, in send
raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /quote/ltp?i=NSE%3AEICHERMOT (Caused by ConnectTimeoutError(, 'Connection to api.kite.trade timed out. (connect timeout=7)'))
Process finished with exit code 1