Streamlit app not able to fetch data from nsepy (library for fetching stock data from Indian stock market web www.nseindia.com)

I am building an application that uses the open-source library nsepy to fetch stock market data from www.nseindia.com.
The same library seems to be working fine when used locally, however when used in Streamlit Cloud, the library is unable to fetch data.
Any fixes or workarounds for this? Would really be helpful!

Do you have it included in your requirements.txt file?

Yes. The library is included in my requirements.txt

Can you provide some code or error messages to clarify further? (Preferably a minimal snippet to show the function that doesn’t work.) Are the app and repository public to view?

These are the logs

and this is the code that fetches it:

from nsepy import get_history as gh
import datetime as dt
from datetime import date
stock=st.text_input('Enter a stock code to start: ')
if stock:
   pass
else:
   st.stop()

start = dt.date(2013,11,1)
end = date.today()

stk_data=pd.DataFrame()
while len(stk_data)<1:
 stk_data = gh(symbol=stock,start=start,end=end)  
 time.sleep(5)
 if len(stk_data)>1:
  break
if len(stk_data)>0:
  st.subheader(f'Historical Price Data of {stock_to_show}')
  fig = go.Figure()
  fig.add_trace(go.Scatter(x=stk_data.index,y=stk_data['Open'],name='Open', mode="lines"))
  fig.add_trace(go.Scatter(x=stk_data.index,y=stk_data['Close'],name='Close', mode="lines"))
  st.plotly_chart(fig,use_container_width=True)
  yesno=st.text_input('Do you want to forecast future stock prices (Y/N)?')
else:
  st.write('Error! If you have entered the wrong Stock Code, Please cross-check and enter the correct NSE stock code! Alternatively, if the server is down, kindly wait and try again after some time.')
  st.stop()

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.