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