Python Forum
How to solve this error "Exceeded 30 redirects" while using "nsepy" library
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to solve this error "Exceeded 30 redirects" while using "nsepy" library
#1
I'm getting this error named "Exceeded 30 redirects" while using "nsepy" library, when I'm trying to fetch data (plz reefer the screenshot)

import nsepy as nse 
from datetime import date 
    stock_price = nse.get_history(symbol='TCS', index = True, start = date(2022,7,30), end = date(2022,8,12))   
Error:
{ "name": "TooManyRedirects", "message": "Exceeded 30 redirects.", "stack": "--------------------------------------------------------------------------- TooManyRedirects Traceback (most recent call last) Cell In[7], line 1 ----> 1 stock_price = nse.get_history(symbol='TCS', index = True, start = date(2022,7,30), end = date(2022,8,12)) File c:\\Users\\RKC\\anaconda3\\Lib\\site-packages\ sepy\\history.py:138, in get_history(symbol, start, end, index, futures, option_type, expiry_date, strike_price, series) 136 return pd.concat((t1.result, t2.result)) 137 else: --> 138 return get_history_quanta(**kwargs) File c:\\Users\\RKC\\anaconda3\\Lib\\site-packages\ sepy\\history.py:143, in get_history_quanta(**kwargs) 141 def get_history_quanta(**kwargs): 142 url, params, schema, headers, scaling = validate_params(**kwargs) --> 143 df = url_to_df(url=url, 144 params=params, 145 schema=schema, 146 headers=headers, scaling=scaling) 147 return df File c:\\Users\\RKC\\anaconda3\\Lib\\site-packages\ sepy\\history.py:151, in url_to_df(url, params, schema, headers, scaling) 150 def url_to_df(url, params, schema, headers, scaling={}): --> 151 resp = url(**params) 152 bs = BeautifulSoup(resp.text, 'lxml') 153 tp = ParseTables(soup=bs, 154 schema=schema, 155 headers=headers, index=\"Date\") File c:\\Users\\RKC\\anaconda3\\Lib\\site-packages\ sepy\\commons.py:167, in URLFetch.__call__(self, *args, **kwargs) 165 url = self.url%(args) 166 if self.method == 'get': --> 167 return self.session.get(url, params=kwargs, proxies = self.proxy ) 168 elif self.method == 'post': 169 if self.json: File c:\\Users\\RKC\\anaconda3\\Lib\\site-packages\\requests\\sessions.py:600, in Session.get(self, url, **kwargs) 592 r\"\"\"Sends a GET request. Returns :class:`Response` object. 593 594 :param url: URL for the new :class:`Request` object. 595 :param \\*\\*kwargs: Optional arguments that ``request`` takes. 596 :rtype: requests.Response 597 \"\"\" 599 kwargs.setdefault(\"allow_redirects\", True) --> 600 return self.request(\"GET\", url, **kwargs) File c:\\Users\\RKC\\anaconda3\\Lib\\site-packages\\requests\\sessions.py:587, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 582 send_kwargs = { 583 \"timeout\": timeout, 584 \"allow_redirects\": allow_redirects, 585 } 586 send_kwargs.update(settings) --> 587 resp = self.send(prep, **send_kwargs) 589 return resp File c:\\Users\\RKC\\anaconda3\\Lib\\site-packages\\requests\\sessions.py:723, in Session.send(self, request, **kwargs) 720 if allow_redirects: 721 # Redirect resolving generator. 722 gen = self.resolve_redirects(r, request, **kwargs) --> 723 history = [resp for resp in gen] 724 else: 725 history = [] File c:\\Users\\RKC\\anaconda3\\Lib\\site-packages\\requests\\sessions.py:723, in <listcomp>(.0) 720 if allow_redirects: 721 # Redirect resolving generator. 722 gen = self.resolve_redirects(r, request, **kwargs) --> 723 history = [resp for resp in gen] 724 else: 725 history = [] File c:\\Users\\RKC\\anaconda3\\Lib\\site-packages\\requests\\sessions.py:191, in SessionRedirectMixin.resolve_redirects(self, resp, req, stream, timeout, verify, cert, proxies, yield_requests, **adapter_kwargs) 188 resp.raw.read(decode_content=False) 190 if len(resp.history) >= self.max_redirects: --> 191 raise TooManyRedirects( 192 f\"Exceeded {self.max_redirects} redirects.\", response=resp 193 ) 195 # Release the connection back into the pool. 196 resp.close() TooManyRedirects: Exceeded 30 redirects." }

Attached Files

Thumbnail(s)
   
Reply
#2
At first glance, it looks like the last time nsepy was modified was in March of 2020.
On that page, the following message is shown by the author:
swapniljariwala Wrote:NSEpy 0.8
Deprecation notice

Caution

Thanks a lot for your support, but I am unable to maintain this library. NSE's old website is also getting deprecated which means NSEPy will cease to work someday when NSE shuts down the old website.

I would suggest that using yfinance to get historical data (although there are caveats here as well) is more reliable.
see:
PranayShah likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using SHAP Library for my LSTM model - "Attribute Error" vatsalmtailor 0 2,150 Jul-13-2022, 04:34 PM
Last Post: vatsalmtailor

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020