Skip to content

AKShare 接口问题报告 - ak.macro_china_nbs_nation #7211

@rigongyibing

Description

@rigongyibing

国际统计局的接口不能工作了。

源代码:
import akshare as ak

macro_china_nbs_nation_df = ak.macro_china_nbs_nation(kind="年度数据", path="人口 > 总人口", period="LAST5")
print(macro_china_nbs_nation_df)

报错:

JSONDecodeError Traceback (most recent call last)
File /opt/anaconda3/envs/myenv/lib/python3.9/site-packages/requests/models.py:974, in Response.json(self, **kwargs)
973 try:
--> 974 return complexjson.loads(self.text, **kwargs)
975 except JSONDecodeError as e:
976 # Catch JSON-related errors and raise as requests.JSONDecodeError
977 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File /opt/anaconda3/envs/myenv/lib/python3.9/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 /opt/anaconda3/envs/myenv/lib/python3.9/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 /opt/anaconda3/envs/myenv/lib/python3.9/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError Traceback (most recent call last)
Cell In[7], line 3
1 import akshare as ak
----> 3 macro_china_nbs_nation_df = ak.macro_china_nbs_nation(kind="年度数据", path="人口 > 总人口", period="LAST5")
4 print(macro_china_nbs_nation_df)

File /opt/anaconda3/envs/myenv/lib/python3.9/site-packages/akshare/economic/macro_china_nbs.py:95, in macro_china_nbs_nation(kind, path, period)
92 dbcode = kind_code[kind]
94 # 获取最终id
---> 95 parent_tree = _get_nbs_tree("zb", dbcode)
96 path_split = path.replace(" ", "").split(">")
97 indicator_id = _get_code_from_nbs_tree(parent_tree, path_split[0])

File /opt/anaconda3/envs/myenv/lib/python3.9/site-packages/akshare/economic/macro_china_nbs.py:35, in _get_nbs_tree(idcode, dbcode)
33 params = {"id": idcode, "dbcode": dbcode, "wdcode": "zb", "m": "getTree"}
34 r = requests.post(url, params=params, verify=False, allow_redirects=True)
---> 35 data_json = r.json()
36 return data_json

File /opt/anaconda3/envs/myenv/lib/python3.9/site-packages/requests/models.py:978, in Response.json(self, **kwargs)
974 return complexjson.loads(self.text, **kwargs)
975 except JSONDecodeError as e:
976 # Catch JSON-related errors and raise as requests.JSONDecodeError
977 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 978 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions