Forums

error while fetching data from nse.com

Getting below error: urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.nseindia.com', port=443): Max retries exceeded with url: /api/option-chain-indices?symbol=BANKNIFTY (Ca used by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))

I am assuming it's because i have free account. Pls let me know if I upgrade my account to 'Hacker', will you be able to whitelist this url?

I mean this url host='www.nseindia.com', port=44

That does not have an API, so you will not be able to access it from a free account.

Thats what my question is. If I upgrade my account, will I be able to access it.

Yes, you will.

Thanks. I have upgraded to paid account. I am running same program. It was stuck at one point. So I forced closed it and below is the message:

12:47 ~/Trade $ python3 straddle.py
^CTraceback (most recent call last):
  File "/home/csomkuwar/Trade/straddle.py", line 20, in <module>
    atmstrike = getatmStrike()
  File "/home/csomkuwar/Trade/straddle.py", line 16, in getatmStrike
    ltp = oi_chain_builder(symbol,"latest","full")[1]
  File "/home/csomkuwar/.local/lib/python3.10/site-packages/nsepython/rahu.py", line 90, in oi_chain_builder
    payload = nse_optionchain_scrapper(symbol)
  File "/home/csomkuwar/.local/lib/python3.10/site-packages/nsepython/rahu.py", line 82, in nse_optionchain_scrapper
    payload = nsefetch('https://www.nseindia.com/api/option-chain-indices?symbol='+symbol)
  File "/home/csomkuwar/.local/lib/python3.10/site-packages/nsepython/rahu.py", line 33, in nsefetch
    output = requests.get(payload,headers=headers).json()
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.10/http/client.py", line 1374, in getresponse
    response.begin()
  File "/usr/local/lib/python3.10/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.10/http/client.py", line 279, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/local/lib/python3.10/socket.py", line 705, in readinto
    return self._sock.recv_into(b)
  File "/usr/local/lib/python3.10/ssl.py", line 1274, in recv_into
    return self.read(nbytes, buffer)
  File "/usr/local/lib/python3.10/ssl.py", line 1130, in read
    return self._sslobj.read(len, buffer)
KeyboardInterrupt

Code that I am running is below:

from nsepython import*
symbol = "BANKNIFTY"
# to get atmstrike using nsepython
def getatmStrike():
    ltp = oi_chain_builder(symbol,"latest","full")[1]
    atmstrike=round(ltp/100)*100
    return atmstrike
atmstrike = getatmStrike()
print(atmstrike)
ceStrike = atmstrike + 300
peStrike = atmstrike - 300

ceLTP = nse_quote_ltp(symbol,"latest","CE",ceStrike)
peLTP = nse_quote_ltp(symbol,"latest","PE",peStrike)

combineFirstPremium = ceLTP+peLTP
print("combined initial premium is:", combineFirstPremium)

Hello, could you try creating a new console and running it from there?

Hi - still facing same issue.

Pls let me know if anything needs to be whitelisted.

It looks like it's NSE blocking. We have seen that in the past. It's not something we can do anything about.

I had asked this same question before upgrading the account

You can't be sure before you try. It's beyond our control. You can downgrade and let us know. We will refund you.

Pls check once - whether https://www.nseindia.com is whitelisted?

Paid accounts are not affected by the allowlist.

@fjl - as mentioned I have downgraded the account. Pls process refund. Would love to upgrade later when nseindia.com data is not blocked.

@csomkuwar -- no problem, we've refunded your last payment; it should be processed within 5-10 working days.

hi @team , is there any update on nsepython allowlist as it is still not allowing me to get data , giving forbidden error

It looks like it's NSE still blocking.