homelab: runpod-lazy UA fix (Cloudflare 403s Python-urllib on proxy.runpod.net) + GITHUB_TOKEN passthrough

229ff4158123f0efba19cd088526636eec30b0a8

permissionBRICK <40219477+permissionBRICK@users.noreply.github.com>

1 files changed, +7 -2Showing whitespace changes
homelab/runpod-lazy-proxy.py+7 -2
@@ -119,7 +119,7 @@ def create_pod(values):
119119 entry = catalog_entry(value)
120120 if entry:
121121 files.extend(entry.get('files') or [])
122122 env = {'HF_TOKEN': HF_TOKEN, 'CIVITAI_TOKEN': os.environ.get('CIVITAI_TOKEN', ''), 'GITHUB_TOKEN': os.environ.get('GITHUB_TOKEN', ''), 'MODEL_KEY': values_key(values)}
123123 if files:
124124 env['MODEL_MANIFEST'] = json.dumps(files)
125125 else:
@@ -146,9 +146,13 @@ def pod_url(pod_id):
146146 return f'https://{pod_id}-8188.proxy.runpod.net'
147147
148148
149+UA = 'Mozilla/5.0 (compatible; runpod-lazy-proxy)'
150+
151+
149152def upstream_ready(pod_id):
150153 try:
151154 withreq = urllib.request.urlopenRequest(pod_url(pod_id) + '/system_stats', timeoutheaders=5) as resp{'User-Agent': UA})
155+ with urllib.request.urlopen(req, timeout=5) as resp:
152156 if resp.status == 200:
153157 data = resp.read()
154158 with open(CACHE_FILE, 'wb') as f:
@@ -351,6 +355,7 @@ class Proxy(BaseHTTPRequestHandler):
351355 return self._reply(502, json.dumps({'error': str(err)}).encode())
352356 try:
353357 req = urllib.request.Request(pod_url(pod_id) + self.path, body, method=self.command)
358+ req.add_header('User-Agent', UA)
354359 for header in ('Content-Type', 'Accept'):
355360 if self.headers.get(header):
356361 req.add_header(header, self.headers[header])