fix: improve IP retrieval logic with retry mechanism and timeout

This commit is contained in:
Nik Afiq 2026-05-12 23:16:40 +09:00
parent 367a456bcc
commit 449b60b38f

View File

@ -95,14 +95,17 @@ spec:
- python3
- -c
- |
import http.server, urllib.request
import http.server, urllib.request, time
class Handler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
ip = 'connecting...'
for _ in range(5):
try:
ip = urllib.request.urlopen('https://ipinfo.io/ip').read().decode().strip()
except Exception as e:
ip = f'error: {e}'
ip = urllib.request.urlopen('https://ipinfo.io/ip', timeout=5).read().decode().strip()
break
except Exception:
time.sleep(2)
body = f'''<!DOCTYPE html>
<html>
<body style="margin:0;display:flex;align-items:center;justify-content:center;height:100vh;