Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I’m getting an error trying to do an API get request, when using JSON RESTful services and Python3. Any help is appreciated. I’m supposed to use API instructions from this website https://nvd.nist.gov/developers/vulnerabilities#. I already have the CVE number, it’s listed in my URL below.

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)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Your URL is wrong. Use

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

full code:

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading