1nchaos / adata

免费开源A股量化数据库; 专注A股,专注量化,向阳而生; 开放、纯净、持续、为Ai(爱)发电。为个人量化交易而生,保卫3000(2500)点,珍惜底部机会......【股票数据,股票行情数据,股票量化数据,股票交易数据,k线行情数据,股票概念数据,股票数据接口,行情数据接口】【多数据源融合,动态设置代理,保障数据高可用性】
https://adata.30006124.xyz
Apache License 2.0
858 stars 120 forks source link

使用多线程获取多个股票的分红信息时候出现报错:JSONDecodeError: Expecting value: line 1 column 1 (char 0) #44

Closed LeslieWuboy closed 9 months ago

LeslieWuboy commented 9 months ago

您好,很感谢您能提供如此强大的工具库,我在处理多线程获取股票分红信息时候,出现报错: in Response.json(self, kwargs) 970 try: --> 971 return complexjson.loads(self.text, kwargs) 972 except JSONDecodeError as e: 973 # Catch JSON-related errors and raise as requests.JSONDecodeError 974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File c:\Users\Leslie\miniconda3\envs\pytorch2\lib\json__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 343 if (cls is None and object_hook is None and 344 parse_int is None and parse_float is None and 345 parse_constant is None and object_pairs_hook is None and not kw): --> 346 return _default_decoder.decode(s) 347 if cls is None:

File c:\Users\Leslie\miniconda3\envs\pytorch2\lib\json\decoder.py:337, in JSONDecoder.decode(self, s, _w) 333 """Return the Python representation of s (a str instance 334 containing a JSON document). 335 336 """ --> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 338 end = _w(s, end).end()

File c:\Users\Leslie\miniconda3\envs\pytorch2\lib\json\decoder.py:355, in JSONDecoder.raw_decode(self, s, idx) ... 973 # Catch JSON-related errors and raise as requests.JSONDecodeError 974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError --> 975 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

麻烦帮忙指导指导,谢谢。

1nchaos commented 9 months ago

能提供更完整的报错信息么,你所提供的信息只能看出来是json转换的时候出现了错误

LeslieWuboy commented 9 months ago

这个是输出的所有日志了,我尝试每两百个开启一次就不会出现这个报错。 不知道是不是获取分红的接口并没有做等待、重试的处理导致的。

1nchaos commented 9 months ago

嗯,数据接口是互联网的接口,存在部分无法获取报错的情况,代码中可以加入异常处理,如果发现接口有返回错误数据可以进行反馈。

LeslieWuboy commented 9 months ago

明白了,还有一个问题就是获取所有股票代码的函数,我看源码是通过读取csv来获取的,为什么我在两个服务器同时执行这个函数却有不同的条数。 如下图,左侧是新获取的条数,右侧是原条数,新获取的反而更少了 image

1nchaos commented 9 months ago

所有代码是缓存和最新数据取交集的,建议在非交易时间获取所有代码。最新的数据可能网络原因获取失败

LeslieWuboy commented 9 months ago

好的,感谢您的指导。