1

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)
5
  • 1
    Did you open the url in the browser? It does not return JSON. Commented Nov 30, 2021 at 21:22
  • That is confusing. I get nothing. The website strictly says it uses JSON. Commented Nov 30, 2021 at 21:24
  • 1
    I think you want to access https://services.nvd.nist.gov/rest/json/cve/1.0/CVE-2021-40463/ Commented Nov 30, 2021 at 21:24
  • have you read the documentation? clearly, your get request is wrong. you need to give the link and then parameters and use approipriate api Commented Nov 30, 2021 at 21:26
  • @sahasrara62 apologies - clearly didn't understand the instructions. I'm just a beginner. Commented Nov 30, 2021 at 21:29

1 Answer 1

3

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))
Sign up to request clarification or add additional context in comments.

2 Comments

Hi sadly, I just didn't enter URL correctly. Code is working on my end. One last question, can you give me tips on how to use PARAMETERS in my code so that it prints better in my terminal? Thanks!
I edited my code. As an alternative - use pprint.pprint. Not sure what you mean by use PARAMETERS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.