我试图导入nsepy库以获取2018年印度国家银行股票(SBIN)的数据,但出现错误。
代码:
from nsepy import get_history
import datetime as dt
sbi_df = get_history(symbol="SBIN", start=dt.date(2018, 1, 1), end=dt.date(2018, 12, 31))
print(sbi_df)
我获取的错误:
Exception in thread Thread-4:
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\commons.py", line 132, in run
self.run()
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\commons.py", line 132, in run
self.result = self._target(*self._args, **self._kwargs)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\history.py", line 138, in get_history
self.result = self._target(*self._args, **self._kwargs)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\history.py", line 138, in get_history
return get_history_quanta(**kwargs)
return get_history_quanta(**kwargs)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\history.py", line 143, in get_history_quanta
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\history.py", line 143, in get_history_quanta
df = url_to_df(url=url,
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\history.py", line 151, in url_to_df
df = url_to_df(url=url,
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\history.py", line 151, in url_to_df
resp = url(**params)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\commons.py", line 167, in __call__
resp = url(**params)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\commons.py", line 167, in __call__
return self.session.get(url, params=kwargs, proxies = self.proxy )
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 600, in get
return self.session.get(url, params=kwargs, proxies = self.proxy )
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 600, in get
return self.request("GET", url, **kwargs)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 587, in request
return self.request("GET", url, **kwargs)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 723, in send
history = [resp for resp in gen]
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 723, in <listcomp>
resp = self.send(prep, **send_kwargs)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 723, in send
history = [resp for resp in gen]
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 191, in resolve_redirects
history = [resp for resp in gen]
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 723, in <listcomp>
raise TooManyRedirects(
requests.exceptions.TooManyRedirects: Exceeded 30 redirects.
history = [resp for resp in gen]
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 191, in resolve_redirects
raise TooManyRedirects(
requests.exceptions.TooManyRedirects: Exceeded 30 redirects.
Exception in thread Thread-3:
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\commons.py", line 132, in run
self.result = self._target(*self._args, **self._kwargs)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\history.py", line 138, in get_history
return get_history_quanta(**kwargs)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\history.py", line 143, in get_history_quanta
df = url_to_df(url=url,
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\history.py", line 151, in url_to_df
resp = url(**params)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\commons.py", line 167, in __call__
return self.session.get(url, params=kwargs, proxies = self.proxy )
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 600, in get
return self.request("GET", url, **kwargs)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 723, in send
history = [resp for resp in gen]
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 723, in <listcomp>
history = [resp for resp in gen]
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\requests\sessions.py", line 191, in resolve_redirects
raise TooManyRedirects(
requests.exceptions.TooManyRedirects: Exceeded 30 redirects.
Exception in thread Thread-2:
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\commons.py", line 132, in run
self.result = self._target(*self._args, **self._kwargs)
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\history.py", line 136, in get_history
return pd.concat((t1.result, t2.result))
AttributeError: 'ThreadReturns' object has no attribute 'result'
Traceback (most recent call last):
File "E:\Quantitative_Trading_Programme\12_Day\1_nsepy.py", line 4, in <module>
sbi_df = get_history(symbol="SBIN", start=dt.date(2018, 1, 1), end=dt.date(2018, 12, 31))
File "E:\Quantitative_Trading_Programme\venv\lib\site-packages\nsepy\history.py", line 136, in get_history
return pd.concat((t1.result, t2.result))
AttributeError: 'ThreadReturns' object has no attribute 'result'
Process finished with exit code 1
1条答案
按热度按时间2ledvvac1#
nsepy已被移动或其他东西,所以它将无法工作尝试一些其他选项,如nsetools