import base64, json import requests from requests.exceptions import HTTPError import random import time user = "root@example.com" password = "Complexpass#123" bas64encoded_creds = base64.b64encode(bytes(user + ":" + password, "utf-8")).decode("utf-8") headers = {"Content-type": "application/json", "Authorization": "Basic " + bas64encoded_creds} org = "default" stream = "demo" zinc_host = "http://localhost:5080" zinc_url = zinc_host + "/api/" + org + "/" + stream + "/_json" for i in range(100): data = [{'metric1': i, 'metric2': i*2, 'metric3': random.randint(1, 100)}] try: response = requests.post(zinc_url, headers=headers, data=json.dumps(data)) # If the response was successful, no Exception will be raised response.raise_for_status() except HTTPError as http_err: print(f'HTTP error occurred: {http_err}') # Python 3.6 except Exception as err: print(f'Other error occurred: {err}') # Python 3.6 else: print('Success!') time.sleep(3)