tenable / pyTenable

Python Library for interfacing into Tenable's platform APIs
https://pytenable.readthedocs.io
MIT License
333 stars 168 forks source link

JSONDecodeError issue on tenable.io.TenableIO.plugins.families #809

Open RegisGraptin opened 6 days ago

RegisGraptin commented 6 days ago

Describe the bug We are using the Tenable IO SDK, to retrieve information on tio.plugins.families(). However, it seems that the internal API request does not managed invalid json response/eventually null or empty response. And in the SDK, it seems that this behaviour is not managed.

Traceback (most recent call last):
  File "/app/.../app_tenableiovm.py", line 195, in get_vulns
    tenable_families=tio.plugins.families(),
                     ^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/tenable/io/plugins.py", line 110, in families
    return self._api.get('plugins/families').json()['families']
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/requests/models.py", line 978, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

To Reproduce We have create a tenable.io.TenableIO object. And we are requesting on tio.plugins.families().

Expected behavior The program should not crash.

System Information (please complete the following information):

SteveMcGrath commented 6 days ago

I cannot recreate this issue.

>>> from tenable.io import TenableIO
>>> tvm = TenableIO()
>>> families = tvm.plugins.families()
>>> families[0]
{'id': 28, 'name': 'AIX Local Security Checks', 'count': 11563}
>>>
RegisGraptin commented 5 days ago

Hello @SteveMcGrath, Thanks for your response. I should have specify that this error does not occur every time. In our prod environment we already notice two times this issue, recently. And it does not seems related to network issue.