import json import requests from retrying import retry @retry def get_device_id(host, gui_port, api_key): syncthing_headers = {'X-API-Key': api_key} response = requests.get("http://" + host + ":" + gui_port + "/rest/system/status", headers=syncthing_headers) return json.loads(response.content)["myID"] @retry def print_debug_info(host, gui_port, api_key): syncthing_headers = {'X-API-Key': api_key} response = requests.get("http://" + host + ":" + gui_port + "/rest/config/devices", headers=syncthing_headers) print("/rest/config/devices: {0}".format(response.content)) def post_devices(device_ids, host, gui_port, api_key): syncthing_headers = {'X-API-Key': api_key} for device_id in device_ids: post_data = { "deviceID": device_id, "name": "Laptop", "addresses": [ "dynamic", "tcp://192.168.1.2:22000" ], "compression": "metadata", "certName": "", "introducer": False, "skipIntroductionRemovals": False, "introducedBy": "", "paused": False, "allowedNetworks": [], "autoAcceptFolders": False, "maxSendKbps": 0, "maxRecvKbps": 0, "ignoredFolders": [], "pendingFolders": [], "maxRequestKiB": 0 } response = requests.post("http://" + host + ":" + gui_port + "/rest/config/devices", headers=syncthing_headers, data=json.dumps(post_data)) print("Attempt to add device {0} to syncthing: {1}".format(device_id, response.content))