Skip to content

Print out response body when a 500 Internal Server Error is received from the pushgateway #96

Description

@bubaflub

I accidentally sent malformed data to a push gateway and got back a 500 Internal Server Error. The body of the response had information about the malformed data but all that was printed was the fact that I got a 500 Internal Server Error.

Example code:

import prometheus_client

reg = prometheus_client.CollectorRegistry()
c1 = prometheus_client.Counter("foo", "bar", labelnames=["baz", "stuff"], registry=reg)
c1.labels({"baz": 1, "stuff": 2}).inc(1)
c2 = prometheus_client.Counter("foo", "bar", labelnames=["baz", "stuff"], registry=reg)
c2.labels({"baz": 3, "stuff": 4}).inc(2)
prometheus_client.push_to_gateway('localhost:8000', job='example', registry=reg)

Output:

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    prometheus_client.push_to_gateway('localhost:8000', job='example', registry=reg)
  File "/usr/local/lib/python2.7/dist-packages/prometheus_client/exposition.py", line 110, in push_to_gateway
    _use_gateway('PUT', gateway, job, registry, grouping_key, timeout)
  File "/usr/local/lib/python2.7/dist-packages/prometheus_client/exposition.py", line 144, in _use_gateway
    resp = build_opener(HTTPHandler).open(request, timeout=timeout)
  File "/usr/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Internal Server Error

Activity

  1. changed the title [-]print out response body when a 500 Internal Server Error is received[/-] [+]Print out response body when a 500 Internal Server Error is received from the pushgateway[/+] on Nov 24, 2016
  2. siddharths2710 commented on Sep 25, 2020

    @siddharths2710

    @brian-brazil , I'd like to know if this issue is still valid, since for the above code pushing malformed data, I get this error instead, which seems to be correct:

      File "issue_96.py", line 6, in <module>
        c2 = prometheus_client.Counter("foo", "bar", labelnames=["baz", "stuff"], registry=reg)
      File "/home/subha/Documents/GitHub/venv/lib/python3.6/site-packages/prometheus_client-0.8.0-py3.6.egg/prometheus_client/metrics.py", line 121, in __init__
      File "/home/subha/Documents/GitHub/venv/lib/python3.6/site-packages/prometheus_client-0.8.0-py3.6.egg/prometheus_client/registry.py", line 31, in register
    ValueError: Duplicated timeseries in CollectorRegistry: {'foo_total', 'foo_created'}
    
  3. siddharths2710 commented on Sep 26, 2020

    @siddharths2710

    Even if a different error is showing up for the same case, I'd say it's still better to get the exception handled altogether so that we can account for similar cases that result in a 500 server error.

  4. added a commit that references this issue on Aug 10, 2026
    4680a7a
  5. added a commit that references this issue on Sep 2, 2026
    1e83839
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions