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
|
- python3
|
||||||
- -c
|
- -c
|
||||||
- |
|
- |
|
||||||
import http.server, urllib.request
|
import http.server, urllib.request, time
|
||||||
|
|
||||||
class Handler(http.server.BaseHTTPRequestHandler):
|
class Handler(http.server.BaseHTTPRequestHandler):
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
try:
|
ip = 'connecting...'
|
||||||
ip = urllib.request.urlopen('https://ipinfo.io/ip').read().decode().strip()
|
for _ in range(5):
|
||||||
except Exception as e:
|
try:
|
||||||
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>
|
body = f'''<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<body style="margin:0;display:flex;align-items:center;justify-content:center;height:100vh;
|
<body style="margin:0;display:flex;align-items:center;justify-content:center;height:100vh;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user