Skip to content

Instantly share code, notes, and snippets.

@rmca
Created May 20, 2014 15:53
Show Gist options
  • Save rmca/5fc7feb596d7b4e579ff to your computer and use it in GitHub Desktop.
Save rmca/5fc7feb596d7b4e579ff to your computer and use it in GitHub Desktop.
import requests
render_url = "http://example.com/render/"
target = 'your.metric.name.here'
from = '00:00_20140101'
until = '23:59_20140520'
# First omit the format so the request will render as PNG (default)
post_dict = {'from': from, 'until': until, 'target': target}
r = requests.post(render_url, data=post_dict)
# Now request JSON format. No matter what we request now it will come back with the previous response,
# for every method other than GET (assuming the cache is cold).
post_dict = {'from': from, 'until': until, 'target': target, 'format': 'json'}
s = requests.post(render_url, data=post_dict)
# Check what the content-type was. For buggy installs this should be image/png.
print s.headers['content-type']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment