fix: improve IP retrieval logic with retry mechanism and timeout
This commit is contained in:
parent
367a456bcc
commit
449b60b38f
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user