使用 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)
uj5u.com熱心網友回復:
你的網址有誤。用
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))
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/370367.html
