waditu / tushare

TuShare is a utility for crawling historical data of China stocks
BSD 3-Clause "New" or "Revised" License
12.87k stars 4.29k forks source link

获取后复权数据接口报错 pandas.errors.EmptyDataError: No columns to parse from file #1698

Open trackcc opened 1 year ago

trackcc commented 1 year ago

df = ts.pro_bar(ts_code='000628.SZ', adj='hfq', start_date='20230318')

[2023-03-24, 16:13:34 CST] {taskinstance.py:1775} ERROR - Task failed with exception Traceback (most recent call last): File "/home/nvidia/anaconda3/envs/quant/lib/python3.8/site-packages/airflow/operators/python.py", line 175, in execute return_value = self.execute_callable() File "/home/nvidia/anaconda3/envs/quant/lib/python3.8/site-packages/airflow/operators/python.py", line 192, in execute_callable return self.python_callable(*self.op_args, self.op_kwargs) File "/home/nvidia/source/respository/application/python/newquant/server/ReadStockDailyHfq.py", line 35, in readDailyHfq df = ts.pro_bar(ts_code=index, adj='hfq', start_date=next_date_string(start_date)) File "/home/nvidia/anaconda3/envs/quant/lib/python3.8/site-packages/tushare/pro/data_pro.py", line 100, in pro_bar api = api if api is not None else pro_api() File "/home/nvidia/anaconda3/envs/quant/lib/python3.8/site-packages/tushare/pro/data_pro.py", line 36, in pro_api token = upass.get_token() File "/home/nvidia/anaconda3/envs/quant/lib/python3.8/site-packages/tushare/util/upass.py", line 27, in get_token df = pd.read_csv(fp) File "/home/nvidia/anaconda3/envs/quant/lib/python3.8/site-packages/pandas/util/_decorators.py", line 211, in wrapper return func(*args, *kwargs) File "/home/nvidia/anaconda3/envs/quant/lib/python3.8/site-packages/pandas/util/_decorators.py", line 331, in wrapper return func(args, kwargs) File "/home/nvidia/anaconda3/envs/quant/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 950, in read_csv return _read(filepath_or_buffer, kwds) File "/home/nvidia/anaconda3/envs/quant/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 605, in _read parser = TextFileReader(filepath_or_buffer, kwds) File "/home/nvidia/anaconda3/envs/quant/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 1442, in init self._engine = self._make_engine(f, self.engine) File "/home/nvidia/anaconda3/envs/quant/lib/python3.8/site-packages/pandas/io/parsers/readers.py", line 1753, in _make_engine return mapping[engine](f, self.options) File "/home/nvidia/anaconda3/envs/quant/lib/python3.8/site-packages/pandas/io/parsers/c_parser_wrapper.py", line 79, in init self._reader = parsers.TextReader(src, **kwds) File "pandas/_libs/parsers.pyx", line 554, in pandas._libs.parsers.TextReader.cinit pandas.errors.EmptyDataError: No columns to parse from file

用Vscode调试报错 image Tushare ID: 483274

jrothschild33 commented 10 months ago

我也遇到了,这是由于tushare读取C盘中的 tk.csv(其实就是token)错误导致的,不清楚为什么要绕一圈读取token,还明文存在了C盘……

目前只能修改源码: 修改tushare中的文件:~\site-packages\tushare\util\upass.py

修改 get_token 函数:

def get_token():
  user_home = os.path.expanduser('~')
  fp = os.path.join(user_home, ct.TOKEN_F_P)
  if os.path.exists(fp):
    return "你的tusahre token"
  else:
    print(ct.TOKEN_ERR_MSG)
    return None