Idirect-Tech / Breeze-Python-SDK

The official Python client library for the ICICI Securities trading APIs
MIT License
60 stars 30 forks source link

SSL certification error #20

Open djsinha2020 opened 1 year ago

djsinha2020 commented 1 year ago

Whenever I use "from breeze_connect import BreezeConnect" in my python code, it throws the below error: urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)>

I am using Anaconda python on Windows 10 machine and below is what I am trying to do:

import yaml
from breeze_connect import BreezeConnect

if __name__ == "__main__":
    stream = open("config.yaml", "r")
    dictionary = yaml.load(stream, Loader=yaml.Loader)
    print(dictionary)
    # Initialize SDK
    breeze = BreezeConnect(api_key=dictionary['api_key'])
    # Generate Session
    breeze.generate_session(api_secret=dictionary['secret_key'], session_token=dictionary['session_key'])
    # Get historical data
    results = breeze.get_historical_data(interval="5minute",
                                         from_date="2023-01-01T07:00:00.000Z",
                                         to_date="2023-02-09T05:30:00.000Z",
                                         stock_code="INDVIX",
                                         exchange_code="NSE",
                                         product_type="cash")
    print(results)

Producing the full error log below:

C:\Users\dhrub\breeze_venv\Scripts\python.exe C:\Users\dhrub\PycharmProjects\pythonProject1\data_download_icici.py 
Traceback (most recent call last):
  File "C:\Users\dhrub\anaconda3\lib\urllib\request.py", line 1346, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\Users\dhrub\anaconda3\lib\http\client.py", line 1285, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\dhrub\anaconda3\lib\http\client.py", line 1331, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\dhrub\anaconda3\lib\http\client.py", line 1280, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\dhrub\anaconda3\lib\http\client.py", line 1040, in _send_output
    self.send(msg)
  File "C:\Users\dhrub\anaconda3\lib\http\client.py", line 980, in send
    self.connect()
  File "C:\Users\dhrub\anaconda3\lib\http\client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "C:\Users\dhrub\anaconda3\lib\ssl.py", line 501, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Users\dhrub\anaconda3\lib\ssl.py", line 1041, in _create
    self.do_handshake()
  File "C:\Users\dhrub\anaconda3\lib\ssl.py", line 1310, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\dhrub\PycharmProjects\pythonProject1\data_download_icici.py", line 2, in <module>
    from breeze_connect import BreezeConnect
  File "C:\Users\dhrub\breeze_venv\lib\site-packages\breeze_connect\__init__.py", line 1, in <module>
    from breeze_connect.breeze_connect import BreezeConnect
  File "C:\Users\dhrub\breeze_venv\lib\site-packages\breeze_connect\breeze_connect.py", line 23, in <module>
    resp = urlopen(config.SECURITY_MASTER_URL)
  File "C:\Users\dhrub\anaconda3\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\dhrub\anaconda3\lib\urllib\request.py", line 517, in open
    response = self._open(req, data)
  File "C:\Users\dhrub\anaconda3\lib\urllib\request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Users\dhrub\anaconda3\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Users\dhrub\anaconda3\lib\urllib\request.py", line 1389, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "C:\Users\dhrub\anaconda3\lib\urllib\request.py", line 1349, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)>

Process finished with exit code 1
isec-nitish commented 1 year ago

Will look into your error in greater detail, but right off the bat: try using the following function/endpoint instead:

response = breeze.get_historical_data_v2(interval="1minute", from_date="2022-01-27 09:00:00", to_date="2022-01-27 16:31:00", stock_code="INDVIX", exchange_code="NSE")

(use your own parameters of course.)

djsinha2020 commented 1 year ago

Will look into your error in greater detail, but right off the bat: try using the following function/endpoint instead:

response = breeze.get_historical_data_v2(interval="1minute", from_date="2022-01-27 09:00:00", to_date="2022-01-27 16:31:00", stock_code="INDVIX", exchange_code="NSE")

(use your own parameters of course.)

Thanks. As per your suggestion, I have this tried this. But the error persists. I think the error is happening at the below line:

from breeze_connect import BreezeConnect

because even the dictionary is not getting printed in the 3rd line of the if block.

djsinha2020 commented 1 year ago

Just an update to the issue. I downgraded to breeze-connect 1.0.21 and the issue went away on it's own. But the moment I upgrade to a later version of breeze-connect, the error again appears.

vrashab-oneture commented 1 year ago

Is your machine under a VPN or under some sort of firewall security?

devudu commented 1 year ago

Same issue. I am not using any VPN. I am using office laptop from home network. So I don't think its a firewall issue. I checked my windows firewall history and none appeared to have blocked.

dp1973 commented 1 year ago

I have been unable to use the API since I think version 13, with the same error.


AttributeError Traceback (most recent call last) Cell In[5], line 1 ----> 1 from breeze_connect import BreezeConnect

File D:\anaconda3\envs\algo\Lib\site-packages\breeze_connect\breeze_connect.py:24 19 import config 22 requests.packages.urllib3.util.connection.HAS_IPV6 = False ---> 24 resp = urlopen(config.SECURITY_MASTER_URL) 25 zipfile = ZipFile(BytesIO(resp.read())) 26 api_endpoint = config.APIEndPoint

AttributeError: module 'config' has no attribute 'SECURITY_MASTER_URL'

wnrao1 commented 1 year ago

Just an update to the issue. I downgraded to breeze-connect 1.0.21 and the issue went away on it's own. But the moment I upgrade to a later version of breeze-connect, the error again appears.

Thanks for the input. I was also struggling with this issue for long. Hope icici will provide this info in breeze api documentation

dhayalramk commented 1 year ago

Any update in this team? Struck here from long time.

ShrikantOneture commented 1 year ago

you are using the oldest version 13