From 382717bb140ff879d137e65d5aab9823a512d0b4 Mon Sep 17 00:00:00 2001 From: Salaheldin Date: Sun, 21 Apr 2019 12:37:09 +0300 Subject: [PATCH] fix updater - Update process was failing due to error in json format - Add check for request error messege --- .gitignore | 1 + classes/cf_api.py | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 816ffc7..b39d668 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea/ ven/ .DS_Store +api_data.json # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/classes/cf_api.py b/classes/cf_api.py index 75a86d9..3f7ebe3 100644 --- a/classes/cf_api.py +++ b/classes/cf_api.py @@ -109,16 +109,26 @@ def update_dns(self, new_ip, current_ip, current_domain, record_type): else: print(ST.os("IP address changed,updating DNS " + record_type + " record")) url = self.api_url + self.domain_token + "/dns_records/" + self.record_token - payload = {"type": record_type, "name": current_domain, "content": new_ip, "ttl": 1, "proxied": "false"} - requests.put(url, data=payload, headers=self.header) - print(ST.hd("Domain " - + current_domain - + " | ip address updated to " - + new_ip + " | DNS record " - + record_type)) - update_status = "updated" - return update_status + payload = '{"type":"' + str(record_type) \ + + '","name":"' + str(current_domain) \ + + '","content":"' + str(new_ip) \ + + '","ttl":1,"proxied":true}' + + response = requests.put(url, data=payload, headers=self.header) + done = json.loads(response.text)["success"] + if done is True: + print(ST.hd("Domain " + + current_domain + + " | ip address updated to " + + new_ip + " | DNS record " + + record_type)) + update_status = "updated" + return update_status + else: + print("Domain update failed") + update_status = "failed" + return update_status # logging @staticmethod def log_(update_status, current_ip, new_ip, current_domain): @@ -132,7 +142,7 @@ def log_(update_status, current_ip, new_ip, current_domain): + update_status + ", ip: " + current_ip + " > " + new_ip + "\n") - elif update_status == "unchanged": + elif update_status == "unchanged" or "failed": log_msg = str(current_domain + " | DNS record " + update_status