Skip to content

Instantly share code, notes, and snippets.

@axolx
Created February 26, 2021 00:31
Show Gist options
  • Save axolx/2b9718c9b56b59ba1a2238b43ce3f75f to your computer and use it in GitHub Desktop.
Save axolx/2b9718c9b56b59ba1a2238b43ce3f75f to your computer and use it in GitHub Desktop.
Sample Python code for making requests to the eTRM API
#!/usr/bin/env python3
"""
Sample Python code for making requests to the eTRM API
"""
import http.client
import json
TOKEN = "SETME"
API_ENDPOINT = "/api/v1/measures/"
# Make HTTP request
print(f"Request: {API_ENDPOINT}")
conn = http.client.HTTPSConnection("www.caetrm.com")
headers = {"Authorization": f"Token {TOKEN}"}
conn.request("GET", API_ENDPOINT, headers=headers)
# Process the HTTP response
response = conn.getresponse()
response_body = json.loads(response.read().decode())
# Print output
print(f"Response status code: {response.status}")
print(json.dumps(response_body, indent=4))
@rosepetal140
Copy link

Is this achievable with JavaScript and to show permutations based on user input?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment