Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Inventory can not recover from getting malformed request #264

Open
viennaa opened this issue Dec 11, 2023 · 1 comment
Open

[BUG] Inventory can not recover from getting malformed request #264

viennaa opened this issue Dec 11, 2023 · 1 comment

Comments

@viennaa
Copy link
Collaborator

viennaa commented Dec 11, 2023

When fetching service_states fails and the reply is malformed, the inventory stops working because the error is not catched.

response.json needs to be catched.

Traceback:

[2023-12-11 09:01:36,943] [ERROR] Problem getting service stats from vrops-vc-... : <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Bad Gateway</title>
</head><body>
<h1>Bad Gateway</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
</p>
</body></html>

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/simplejson/__init__.py", line 514, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/simplejson/decoder.py", line 386, in decode
    obj, end = self.raw_decode(s)
               ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/simplejson/decoder.py", line 416, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/vrops-exporter/./inventory.py", line 96, in <module>
    InventoryBuilder(os.environ.get('TARGET'), os.environ['PORT'], os.environ['SLEEP'])
  File "/vrops-exporter/inventory/Builder.py", line 34, in __init__
    self.query_inventory_permanent()
  File "/vrops-exporter/inventory/Builder.py", line 59, in query_inventory_permanent
    self.query_vrops(self.target, vrops_short_name, self.iteration)
  File "/vrops-exporter/inventory/Builder.py", line 119, in query_vrops
    Vrops.get_service_states(vrops, target, token)
  File "/vrops-exporter/tools/Vrops.py", line 672, in get_service_states
    return response.json(), response.status_code, response.elapsed.total_seconds()
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
@viennaa
Copy link
Collaborator Author

viennaa commented Mar 4, 2024

@kevin-fischer good first issue :)

@kevin-fischer kevin-fischer removed their assignment Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants