homelab: runpod-lazy UA fix (Cloudflare 403s Python-urllib on proxy.runpod.net) + GITHUB_TOKEN passthrough
| @@ -119,7 +119,7 @@ def create_pod(values): | ||
| 119 | 119 | entry = catalog_entry(value) |
| 120 | 120 | if entry: |
| 121 | 121 | files.extend(entry.get('files') or []) |
| 122 | 122 | env = {'HF_TOKEN': HF_TOKEN, 'CIVITAI_TOKEN': os.environ.get('CIVITAI_TOKEN', ''), 'GITHUB_TOKEN': os.environ.get('GITHUB_TOKEN', ''), 'MODEL_KEY': values_key(values)} |
| 123 | 123 | if files: |
| 124 | 124 | env['MODEL_MANIFEST'] = json.dumps(files) |
| 125 | 125 | else: |
| @@ -146,9 +146,13 @@ def pod_url(pod_id): | ||
| 146 | 146 | return f'https://{pod_id}-8188.proxy.runpod.net' |
| 147 | 147 | |
| 148 | 148 | |
| 149 | +UA = 'Mozilla/5.0 (compatible; runpod-lazy-proxy)' | |
| 150 | + | |
| 151 | + | |
| 149 | 152 | def upstream_ready(pod_id): |
| 150 | 153 | try: |
| 151 | 154 | 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: | |
| 152 | 156 | if resp.status == 200: |
| 153 | 157 | data = resp.read() |
| 154 | 158 | with open(CACHE_FILE, 'wb') as f: |
| @@ -351,6 +355,7 @@ class Proxy(BaseHTTPRequestHandler): | ||
| 351 | 355 | return self._reply(502, json.dumps({'error': str(err)}).encode()) |
| 352 | 356 | try: |
| 353 | 357 | req = urllib.request.Request(pod_url(pod_id) + self.path, body, method=self.command) |
| 358 | + req.add_header('User-Agent', UA) | |
| 354 | 359 | for header in ('Content-Type', 'Accept'): |
| 355 | 360 | if self.headers.get(header): |
| 356 | 361 | req.add_header(header, self.headers[header]) |