akfamily / akshare

AKShare is an elegant and simple financial data interface library for Python, built for human beings! 开源财经数据接口库
https://akshare.akfamily.xyz
MIT License
8.7k stars 1.79k forks source link

currency_hist 接口错误 #4994

Closed aarenw closed 1 week ago

aarenw commented 1 week ago

AK 版本是1.14.14

运行 ak.currency_hist(), 返回如下错误

{
    "name": "TypeError",
    "message": "the JSON object must be str, bytes or bytearray, not dict",
    "stack": "---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 4
      1 # usdjpyhis=ak.currency_hist(symbol=\"usd-jpy\", period=\"每日\", start_date=\"20100101\",  end_date=\"20240625\")
      2 # usdjpyhis = ak.currency_hist(symbol=\"usd-jpy\", period=\"每日\", start_date=\"20050101\", end_date=\"20200117\" )
      3 print(ak.__version__)
----> 4 usdjpyhis = ak.currency_hist()

File ~/miniconda3/envs/ds/lib/python3.9/site-packages/akshare/fx/currency_investing.py:84, in currency_hist(symbol, period, start_date, end_date)
     82 start_date = \"-\".join([start_date[:4], start_date[4:6], start_date[6:]])
     83 end_date = \"-\".join([end_date[:4], end_date[4:6], end_date[6:]])
---> 84 code = currency_hist_area_index_name_code(symbol)
     85 url = f\"https://api.investing.com/api/financialdata/historical/{code}\"
     86 period_map = {\"每日\": \"Daily\", \"每周\": \"Weekly\", \"每月\": \"Monthly\"}

File ~/miniconda3/envs/ds/lib/python3.9/site-packages/akshare/fx/currency_investing.py:56, in currency_hist_area_index_name_code(symbol)
     54 data_text = soup.find(\"script\", attrs={\"id\": \"__NEXT_DATA__\"}).text
     55 data_json = json.loads(data_text)
---> 56 code = json.loads(data_json[\"props\"][\"pageProps\"][\"state\"])[\"dataStore\"][
     57     \"pageInfoStore\"
     58 ][\"identifiers\"][\"instrument_id\"]
     59 return code

File ~/miniconda3/envs/ds/lib/python3.9/json/__init__.py:339, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    337 else:
    338     if not isinstance(s, (bytes, bytearray)):
--> 339         raise TypeError(f'the JSON object must be str, bytes or bytearray, '
    340                         f'not {s.__class__.__name__}')
    341     s = s.decode(detect_encoding(s), 'surrogatepass')
    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):

TypeError: the JSON object must be str, bytes or bytearray, not dict"
}
aarenw commented 1 week ago

升级到1.14.16, 问题依然存在。