import requests import sys import re file_name = sys.argv[1] print(file_name) dptFile = open(file_name, 'r') lines = dptFile.readlines() subject = re.split("(?<=_)(.+)(?=\.)", file_name)[1] jsonString = '{\" + subject + \": [' # Concatenate data for line in lines: content = line.split(',') jsonString += '[' + str(content[0]) + ', ' + str(content[1].strip()) + '],' # Remove last comma jsonString = jsonString[:-1] jsonString += ']}' headers = { 'accept': '*/*', 'hono-ttd': '10', 'Authorization': 'Basic ZGVmaW5tYUB0MzhiYmNjZDE2MjE3NDViODgxMTk5ZGI2ZWQzZGFiNmE6RGVGaW5NYWNoZW4yMDIwIQ==', 'Content-Type': 'application/json', } response = requests.post('https://http.bosch-iot-hub.com/telemetry', headers=headers, data=jsonString) print(response)