Giter VIP home page Giter VIP logo

Comments (13)

Micro-sheep avatar Micro-sheep commented on August 28, 2024

原因大概是因为json的decoder有问题,

debug到decorder文件的这部分

def raw_decode(self, s, idx=0, _w=WHITESPACE.match, _PY3=PY3):

    """Decode a JSON document from ``s`` (a ``str`` or ``unicode``

    beginning with a JSON document) and return a 2-tuple of the Python

    representation and the index in ``s`` where the document ended.

    Optionally, ``idx`` can be used to specify an offset in ``s`` where

    the JSON document begins.



    This can be used to decode a JSON document from a string that may

    have extraneous data at the end.



    """

    if idx < 0:

        # Ensure that raw_decode bails on negative indexes, the regex

        # would otherwise mask this behavior. #98

        raise JSONDecodeError('Expecting value', s, idx)

    if _PY3 and not isinstance(s, str):

        raise TypeError("Input string must be text, not bytes")

    # strip UTF-8 bom

    if len(s) > idx:

        ord0 = ord(s[idx])

        if ord0 == 0xfeff:

            idx += 1

        elif ord0 == 0xef and s[idx:idx + 3] == '\xef\xbb\xbf':

            idx += 3

    return self.scan_once(s, idx=_w(s, idx).end())

报错是

JSONDecodeError: Expecting value

把核心调用代码发一下,我本地试试看,还有提供一下 python 版本、操作系统以及 efinance 的版本号。

from efinance.

TinkerJueBerg avatar TinkerJueBerg commented on August 28, 2024

原因大概是因为json的decoder有问题,
debug到decorder文件的这部分
def raw_decode(self, s, idx=0, _w=WHITESPACE.match, _PY3=PY3):

    """Decode a JSON document from ``s`` (a ``str`` or ``unicode``

    beginning with a JSON document) and return a 2-tuple of the Python

    representation and the index in ``s`` where the document ended.

    Optionally, ``idx`` can be used to specify an offset in ``s`` where

    the JSON document begins.



    This can be used to decode a JSON document from a string that may

    have extraneous data at the end.



    """

    if idx < 0:

        # Ensure that raw_decode bails on negative indexes, the regex

        # would otherwise mask this behavior. #98

        raise JSONDecodeError('Expecting value', s, idx)

    if _PY3 and not isinstance(s, str):

        raise TypeError("Input string must be text, not bytes")

    # strip UTF-8 bom

    if len(s) > idx:

        ord0 = ord(s[idx])

        if ord0 == 0xfeff:

            idx += 1

        elif ord0 == 0xef and s[idx:idx + 3] == '\xef\xbb\xbf':

            idx += 3

    return self.scan_once(s, idx=_w(s, idx).end())

报错是
JSONDecodeError: Expecting value

把核心调用代码发一下,我本地试试看,还有提供一下 python 版本、操作系统以及 efinance 的版本号。

stock_codes= '招商积余' # 001914也一样
df = ef.stock.get_quote_history(stock_codes=code,klt=1)
这步调用就直接报错了,奇怪的是它是间歇性的,一段时间内怎么运行都bug。过了一会运行就可能没错。
py3.8 ef0.3.8 mac spyder和pycharm都有这个问题。
麻烦大佬debug了哈

from efinance.

Micro-sheep avatar Micro-sheep commented on August 28, 2024

我在 Windows 系统的 python 3.7 版本下跑了 100 次,均是正常的,在 docker 里面的 miniconda 管理的 python 3.7 版本也是正常。测试代码如下

import efinance as ef
# 对同一只股票测试 100 次
ef.stock.get_quote_history(['招商积余']*100) 

from efinance.

TinkerJueBerg avatar TinkerJueBerg commented on August 28, 2024

你试一下等几分钟再跑一次,这个偶尔会通,似乎和时间段有关,原因应该是获取请求但是没有返回数据。

from efinance.

Micro-sheep avatar Micro-sheep commented on August 28, 2024

你试一下等几分钟再跑一次,这个偶尔会通,似乎和时间段有关,原因应该是获取请求但是没有返回数据。

klt=1 的话,如果是交易日,得在非早上 9点到9点半之间运行。因为这个时间段东方财富会重置分钟线数据。

from efinance.

TinkerJueBerg avatar TinkerJueBerg commented on August 28, 2024

现在也不能用,凡是交易时段就不用能是吧,,

from efinance.

Micro-sheep avatar Micro-sheep commented on August 28, 2024

刚刚也试了,没啥问题的
image
如果你的还是不行,可以试试重新安装一遍 efinance

from efinance.

Micro-sheep avatar Micro-sheep commented on August 28, 2024

原因大概是因为json的decoder有问题,
debug到decorder文件的这部分
def raw_decode(self, s, idx=0, _w=WHITESPACE.match, _PY3=PY3):

    """Decode a JSON document from ``s`` (a ``str`` or ``unicode``

    beginning with a JSON document) and return a 2-tuple of the Python

    representation and the index in ``s`` where the document ended.

    Optionally, ``idx`` can be used to specify an offset in ``s`` where

    the JSON document begins.



    This can be used to decode a JSON document from a string that may

    have extraneous data at the end.



    """

    if idx < 0:

        # Ensure that raw_decode bails on negative indexes, the regex

        # would otherwise mask this behavior. #98

        raise JSONDecodeError('Expecting value', s, idx)

    if _PY3 and not isinstance(s, str):

        raise TypeError("Input string must be text, not bytes")

    # strip UTF-8 bom

    if len(s) > idx:

        ord0 = ord(s[idx])

        if ord0 == 0xfeff:

            idx += 1

        elif ord0 == 0xef and s[idx:idx + 3] == '\xef\xbb\xbf':

            idx += 3

    return self.scan_once(s, idx=_w(s, idx).end())

报错是
JSONDecodeError: Expecting value

把核心调用代码发一下,我本地试试看,还有提供一下 python 版本、操作系统以及 efinance 的版本号。

stock_codes= '招商积余' # 001914也一样
df = ef.stock.get_quote_history(stock_codes=code,klt=1)
这步调用就直接报错了,奇怪的是它是间歇性的,一段时间内怎么运行都bug。过了一会运行就可能没错。
py3.8 ef0.3.8 mac spyder和pycharm都有这个问题。
麻烦大佬debug了哈

提供一下属于 efinance 的报错代码。原生的这些库基本上不会有问题,我得知道是 efinance 里面的哪一部分代码报错。

from efinance.

TinkerJueBerg avatar TinkerJueBerg commented on August 28, 2024

Traceback (most recent call last):

File "/Users/ttt/.spyder-py3/temp.py", line 47, in
query()

File "/Users/ttt/.spyder-py3/temp.py", line 29, in query
df = ef.stock.get_quote_history(stock_codes=code,klt=1)

File "/Users/ttt/opt/anaconda3/lib/python3.8/site-packages/efinance/stock/getter.py", line 235, in get_quote_history
df = get_quote_history_for_stock(

File "/Users/ttt/opt/anaconda3/lib/python3.8/site-packages/efinance/common/getter.py", line 190, in get_quote_history
return get_quote_history_single(codes,

File "/Users/ttt/opt/anaconda3/lib/python3.8/site-packages/efinance/utils/init.py", line 33, in run
values = func(*args, **kwargs)

File "/Users/ttt/opt/anaconda3/lib/python3.8/site-packages/efinance/common/getter.py", line 87, in get_quote_history_single
json_response = session.get(

File "/Users/ttt/opt/anaconda3/lib/python3.8/site-packages/requests/models.py", line 910, in json
return complexjson.loads(self.text, **kwargs)

File "/Users/ttt/opt/anaconda3/lib/python3.8/site-packages/simplejson/init.py", line 525, in loads
return _default_decoder.decode(s)

File "/Users/ttt/opt/anaconda3/lib/python3.8/site-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)

File "/Users/ttt/opt/anaconda3/lib/python3.8/site-packages/simplejson/decoder.py", line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())

JSONDecodeError: Expecting value

from efinance.

TinkerJueBerg avatar TinkerJueBerg commented on August 28, 2024

那我理解就是run 这个函数没有读到值

from efinance.

Micro-sheep avatar Micro-sheep commented on August 28, 2024

那我理解就是run 这个函数没有读到值

你试一下别的股票代码,然后klt 保持默认,如果可以,那就重新安装 efinace 再试之前报错的代码,避免搜索缓存更新有问题。如果还是不行,我再远程帮你看看吧,我这边没法复现问题。

from efinance.

TinkerJueBerg avatar TinkerJueBerg commented on August 28, 2024

我知道了,你的url请求的这个域名和api返回经常是502就是报错,用浏览器和requests请求都试过了。
'http://push2his.eastmoney.com/api/qt/stock/fflow/daykline/get'。'http://push2his.eastmoney.com/

from efinance.

Micro-sheep avatar Micro-sheep commented on August 28, 2024

我知道了,你的url请求的这个域名和api返回经常是502就是报错,用浏览器和requests请求都试过了。 'http://push2his.eastmoney.com/api/qt/stock/fflow/daykline/get'。'http://push2his.eastmoney.com/

嗯,这估计跟网络有关吧。国内网络直连一般是正常的,至少我的没有出现过问题,无论使用的是个人电脑、服务器、手机热点的网络。你检查一下是不是用了代理。

from efinance.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.