Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

(GITHUB-89) Do not throw ValueError on authentication error during POST #132

Merged
merged 1 commit into from
Aug 17, 2016
Merged

(GITHUB-89) Do not throw ValueError on authentication error during POST #132

merged 1 commit into from
Aug 17, 2016

Conversation

jhaegg
Copy link

@jhaegg jhaegg commented Aug 17, 2016

Fix for issue #89

Before:

>>> import librato
>>> conn = librato.connect("user", "invalidcredential")
>>> conn.list_metrics()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../librato/__init__.py", line 222, in list_metrics
    resp = self._mexe("metrics", query_props=query_props)
  File ".../librato/__init__.py", line 191, in _mexe
    resp_data, success, backoff = self._process_response(resp, backoff)
  File ".../librato/__init__.py", line 171, in _process_response
    raise exceptions.get(resp.status, resp_data)
librato.exceptions.Unauthorized: [401] request: Authorization Required

>>> conn.submit("gauge_1", 1, description="desc 1")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../librato/__init__.py", line 246, in submit
    self._mexe("metrics", method="POST", query_props=payload)
  File ".../librato/__init__.py", line 191, in _mexe
    resp_data, success, backoff = self._process_response(resp, backoff)
  File ".../librato/__init__.py", line 167, in _process_response
    resp_data = json.loads(body.decode(_getcharset(resp)))
  File "/usr/lib64/python3.5/json/__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python3.5/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python3.5/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

After:

>>> import librato
>>> conn = librato.connect("user", "invalidcredential")
>>> conn.list_metrics()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../python-librato/librato/__init__.py", line 219, in list_metrics
    resp = self._mexe("metrics", query_props=query_props)
  File ".../python-librato/librato/__init__.py", line 188, in _mexe
    resp_data, success, backoff = self._process_response(resp, backoff)
  File ".../python-librato/librato/__init__.py", line 168, in _process_response
    raise exceptions.get(resp.status, resp_data)
librato.exceptions.Unauthorized: [401] request: Authorization Required

>>> conn.submit("gauge_1", 1, description="desc 1")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../python-librato/librato/__init__.py", line 243, in submit
    self._mexe("metrics", method="POST", query_props=payload)
  File ".../python-librato/librato/__init__.py", line 188, in _mexe
    resp_data, success, backoff = self._process_response(resp, backoff)
  File ".../python-librato/librato/__init__.py", line 168, in _process_response
    raise exceptions.get(resp.status, resp_data)
librato.exceptions.Unauthorized: [401] Credentials are required to access this resource.

@drio
Copy link
Contributor

drio commented Aug 17, 2016

Outstanding. I'll merge it later today. Good work. 👏

@drio drio merged commit 72a95c7 into librato:master Aug 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants