Skip to content

Commit b35bf97

Browse files
committed
Added error suppression
1 parent eff8af8 commit b35bf97

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

main.py

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,34 @@ def refresh(self):
5050
else:
5151
print("Your ipv4 address is:", self.__v4)
5252

53-
describe_v4 = DescribeDomainRecordsRequest()
54-
describe_v4.set_accept_format('json')
53+
try:
54+
describe_v4 = DescribeDomainRecordsRequest()
55+
describe_v4.set_accept_format('json')
5556

56-
describe_v4.set_DomainName(self.domain)
57-
describe_v4.set_RRKeyWord(self.record)
58-
describe_v4.set_TypeKeyWord("A")
57+
describe_v4.set_DomainName(self.domain)
58+
describe_v4.set_RRKeyWord(self.record)
59+
describe_v4.set_TypeKeyWord("A")
5960

60-
describeback_v4 = self.__client.do_action_with_exception(describe_v4)
61+
describeback_v4 = self.__client.do_action_with_exception(describe_v4)
6162

62-
recordlist_v4 = json.loads(describeback_v4)
63-
recordid_v4 = recordlist_v4['DomainRecords']['Record'][0]['RecordId']
64-
value_v4 = recordlist_v4['DomainRecords']['Record'][0]['Value']
63+
recordlist_v4 = json.loads(describeback_v4)
64+
recordid_v4 = recordlist_v4['DomainRecords']['Record'][0]['RecordId']
65+
value_v4 = recordlist_v4['DomainRecords']['Record'][0]['Value']
6566

66-
if value_v4 != self.__v4:
67-
print('Your ipv4 address has been changed, update now.')
68-
update_v4 = UpdateDomainRecordRequest()
69-
update_v4.set_accept_format('json')
67+
if value_v4 != self.__v4:
68+
print('Your ipv4 address has been changed, update now.')
69+
update_v4 = UpdateDomainRecordRequest()
70+
update_v4.set_accept_format('json')
7071

71-
update_v4.set_RecordId(recordid_v4)
72-
update_v4.set_Value(self.__v4)
73-
update_v4.set_Type("A")
74-
update_v4.set_RR(self.record)
72+
update_v4.set_RecordId(recordid_v4)
73+
update_v4.set_Value(self.__v4)
74+
update_v4.set_Type("A")
75+
update_v4.set_RR(self.record)
7576

76-
self.__client.do_action_with_exception(update_v4)
77-
print('Your ipv4 record has been updated successfully.')
77+
self.__client.do_action_with_exception(update_v4)
78+
print('Your ipv4 record has been updated successfully.')
79+
except Exception as e:
80+
print("Failed to update your ipv4 record,", e)
7881

7982

8083
# Get local public ipv6 address
@@ -86,31 +89,34 @@ def refresh(self):
8689
else:
8790
print("Your ipv6 address is:", self.__v6)
8891

89-
describe_v6 = DescribeDomainRecordsRequest()
90-
describe_v6.set_accept_format('json')
92+
try:
93+
describe_v6 = DescribeDomainRecordsRequest()
94+
describe_v6.set_accept_format('json')
9195

92-
describe_v6.set_DomainName(self.domain)
93-
describe_v6.set_RRKeyWord(self.record)
94-
describe_v6.set_TypeKeyWord("AAAA")
96+
describe_v6.set_DomainName(self.domain)
97+
describe_v6.set_RRKeyWord(self.record)
98+
describe_v6.set_TypeKeyWord("AAAA")
9599

96-
describeback_v6 = self.__client.do_action_with_exception(describe_v6)
100+
describeback_v6 = self.__client.do_action_with_exception(describe_v6)
97101

98-
recordlist_v6 = json.loads(describeback_v6)
99-
recordid_v6 = recordlist_v6['DomainRecords']['Record'][0]['RecordId']
100-
value_v6 = recordlist_v6['DomainRecords']['Record'][0]['Value']
102+
recordlist_v6 = json.loads(describeback_v6)
103+
recordid_v6 = recordlist_v6['DomainRecords']['Record'][0]['RecordId']
104+
value_v6 = recordlist_v6['DomainRecords']['Record'][0]['Value']
101105

102-
if value_v6 != self.__v6:
103-
print('Your ipv6 address has been changed, update now.')
104-
update_v6 = UpdateDomainRecordRequest()
105-
update_v6.set_accept_format('json')
106+
if value_v6 != self.__v6:
107+
print('Your ipv6 address has been changed, update now.')
108+
update_v6 = UpdateDomainRecordRequest()
109+
update_v6.set_accept_format('json')
106110

107-
update_v6.set_RecordId(recordid_v6)
108-
update_v6.set_Value(self.__v6)
109-
update_v6.set_Type("AAAA")
110-
update_v6.set_RR(self.record)
111+
update_v6.set_RecordId(recordid_v6)
112+
update_v6.set_Value(self.__v6)
113+
update_v6.set_Type("AAAA")
114+
update_v6.set_RR(self.record)
111115

112-
self.__client.do_action_with_exception(update_v6)
113-
print('Your ipv6 record has been updated successfully.')
116+
self.__client.do_action_with_exception(update_v6)
117+
print('Your ipv6 record has been updated successfully.')
118+
except Exception as e:
119+
print("Failed to update your ipv4 record,", e)
114120

115121
if __name__ == "__main__":
116122
dns = AliDDNS("MainDomain.com", "SubDomain", "AccessKey ID", "AccessKey Secret")

0 commit comments

Comments
 (0)