簡體   English   中英

使用 API GET 請求以及 JSON 和 Python 時收到錯誤

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

在使用 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)

您的 URL 是錯誤的。 利用

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

完整代碼:

import requests

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM