使用 API GET 请求时收到错误,其中 JSON 和 Python

Error received when using an API GET request, with JSON and Python

在使用 JSON RESTful 服务和 Python3 时,我尝试执行 API get 请求时出错。任何帮助表示赞赏。我应该使用来自该网站 https://nvd.nist.gov/developers/vulnerabilities# 的 API 说明。我已经有了 CVE 编号,它列在我下面的 URL 中。

import requests
import json

response = requests.get('https://services.nvd.nist.gov/rest/json/CVE-2021-40463/1.0/').json()

print (response)

File "/Users/xxxx/Desktop/UT_Code/UT_Homework.py", line 4, in <module>
    response = requests.get('https://services.nvd.nist.gov/rest/json/CVE-2021-40463/1.0/').json()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/models.py", line 910, in json
    return complexjson.loads(self.text, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/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)

你的URL错了。使用

https://services.nvd.nist.gov/rest/json/cve/1.0/CVE-2021-40463/

完整代码:

import requests
import json

response = requests.get('https://services.nvd.nist.gov/rest/json/cve/1.0/CVE-2021-40463')
data = response.json()
print(json.dumps(data, indent=4))