【发布时间】:2022-01-07 13:42:57
【问题描述】:
在使用 JSON RESTful 服务和 Python3 时,我在尝试执行 API 获取请求时遇到错误。任何帮助表示赞赏。我应该使用来自这个网站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)
【问题讨论】:
-
你在浏览器中打开网址了吗?它不返回 JSON。
-
这令人困惑。我什么都得不到。该网站严格说它使用 JSON。
-
我想你想访问
https://services.nvd.nist.gov/rest/json/cve/1.0/CVE-2021-40463/ -
您阅读过文档吗?显然,您的获取请求是错误的。您需要提供链接,然后提供参数并使用适当的 api
-
@sahasrara62 道歉 - 显然不理解说明。我只是一个初学者。