Skip to content

Commit

Permalink
Merge pull request #52 from mietzen/fix-issue-51
Browse files Browse the repository at this point in the history
Have try block inside the loop, fixes #51
  • Loading branch information
mietzen committed Apr 25, 2024
2 parents ff122e5 + a648333 commit 2d0e57e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions porkbun_ddns/porkbun_ddns.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,28 @@ def get_public_ips(self) -> list:
urls = ['https://v4.ident.me',
'https://api.ipify.org',
'https://ipv4.icanhazip.com']
try:
for url in urls:
for url in urls:
try:
with urllib.request.urlopen(url) as response:
if response.getcode() == 200:
public_ips.append(response.read().decode('utf-8'))
break
logger.warning("Failed to retrieve IPv4 Address from %s! HTTP status code: %s", url, str(response.code()))
except URLError:
logger.warning("Can't reach IPv4 Address! Check IPv4 connectivity!")
except URLError as err:
logger.warning("Error reaching %s! Error: %s", url, repr(err))
if self.ipv6:
urls = ['https://v6.ident.me',
'https://api6.ipify.org',
'https://ipv6.icanhazip.com']
try:
for url in urls:
for url in urls:
try:
with urllib.request.urlopen(url) as response:
if response.getcode() == 200:
public_ips.append(response.read().decode('utf-8'))
break
logger.warning("Failed to retrieve IPv6 Address from %s! HTTP status code: %s", url, str(response.code()))
except URLError:
logger.warning("Can't reach IPv6 Address! Check IPv6 connectivity!")
except URLError as err:
logger.warning("Error reaching %s! Error: %s", url, repr(err))

public_ips = set(public_ips)

Expand Down

0 comments on commit 2d0e57e

Please sign in to comment.