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

调用数据时会出现JSONDecodeError #1245

Open Chaoji112 opened 4 years ago

Chaoji112 commented 4 years ago

【第一次编辑Issue,格式不对还请谅解】 版本:Spyder 3.3.6 + python 3.7 问题:在通过端口调取数据时会出现JSONDecodeError (目前使用过daily和balancesheet),重新运行代码有时可以解决,有时不行。

出错情况: while j<count: temp = pd.DataFrame() code = tushare_data.loc[j, 'ts_code'] start = tushare_data.loc[j, 'issue_date'] end = "{}1231".format(pd.to_datetime(start).year)
print('Getting company data for {}'.format(tushare_data.loc[j, 'ts_code'])) temp = pro.balancesheet(ts_code=code,start_date=start,end_date=end) company_data = company_data.append(temp,ignore_index=True) j=j+1

Error Output: Traceback (most recent call last): File "", line 7, in temp = pro.balancesheet(ts_code=code,start_date=start,end_date=end) File "D:\Anaconda\lib\site-packages\tushare\pro\client.py", line 41, in query result = json.loads(res.text) File "D:\Anaconda\lib\json__init__.py", line 348, in loads return _default_decoder.decode(s) File "D:\Anaconda\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "D:\Anaconda\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None JSONDecodeError: Expecting value

还是python新手,不确定是哪方面的问题。

li-yong commented 4 years ago

issue +1

pip install tushare --upgrade

li-yong commented 4 years ago

pro = ts.pro_api()

pro.trade_cal(exchange='', start_date='20180101', end_date='20181231') Traceback (most recent call last): File "", line 1, in File "/home/ryan/anaconda3/lib/python3.7/site-packages/tushare/pro/client.py", line 41, in query result = json.loads(res.text) File "/home/ryan/anaconda3/lib/python3.7/json/init.py", line 348, in loads return _default_decoder.decode(s) File "/home/ryan/anaconda3/lib/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/home/ryan/anaconda3/lib/python3.7/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

li-yong commented 4 years ago

Similar to issue #1232

li-yong commented 4 years ago

check your network. or switch to another network.

This is caused by network, looks the network disallowed the connection to tushare server. After switching to another network, the issue no longer exist.

Chaoji112 commented 4 years ago

check your network. or switch to another network.

This is caused by network, looks the network disallowed the connection to tushare server. After switching to another network, the issue no longer exist.

Mine still exist tho as I tried using this both at work and at home and the issue remained, thank you for the reply tho :)