jefffffff9 Claude Sonnet 4.6 commited on
Commit
670a1d1
·
1 Parent(s): 7f169d8

Fix Kaggle trigger 401: pass credentials as env vars instead of KAGGLE_CONFIG_DIR

Browse files

Newer kaggle CLI ignores KAGGLE_CONFIG_DIR; pass KAGGLE_USERNAME and KAGGLE_KEY
directly as environment variables so the CLI authenticates correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +14 -24
app.py CHANGED
@@ -19,7 +19,6 @@ import io
19
  import json
20
  import os
21
  import sys
22
- import tempfile
23
  import threading
24
  from datetime import datetime, timezone
25
  from pathlib import Path
@@ -619,7 +618,7 @@ def _trigger_kaggle_training(lang: str = "bam") -> str:
619
  if not KAGGLE_USERNAME or not KAGGLE_KEY:
620
  return "⚠️ KAGGLE_USERNAME / KAGGLE_KEY not set in Space secrets."
621
 
622
- import subprocess, tempfile, shutil
623
 
624
  notebooks_dir = ROOT / "notebooks"
625
  meta_file = notebooks_dir / "kernel-metadata.json"
@@ -630,28 +629,19 @@ def _trigger_kaggle_training(lang: str = "bam") -> str:
630
  if not meta_file.exists():
631
  return "❌ notebooks/kernel-metadata.json not found in Space."
632
 
633
- # Write kaggle.json to a temp dir so the CLI authenticates
634
- with tempfile.TemporaryDirectory() as tmpdir:
635
- kaggle_cfg = Path(tmpdir) / ".kaggle"
636
- kaggle_cfg.mkdir()
637
- creds_file = kaggle_cfg / "kaggle.json"
638
- creds_file.write_text(
639
- json.dumps({"username": KAGGLE_USERNAME, "key": KAGGLE_KEY}),
640
- encoding="utf-8",
641
- )
642
- creds_file.chmod(0o600)
643
-
644
- env = {
645
- **__import__("os").environ,
646
- "KAGGLE_CONFIG_DIR": str(kaggle_cfg),
647
- "PYTHONUTF8": "1",
648
- "PYTHONIOENCODING": "utf-8",
649
- }
650
-
651
- result = subprocess.run(
652
- ["kaggle", "kernels", "push", "-p", str(notebooks_dir)],
653
- capture_output=True, text=True, timeout=60, env=env,
654
- )
655
 
656
  if result.returncode == 0:
657
  output = (result.stdout or "").strip()
 
19
  import json
20
  import os
21
  import sys
 
22
  import threading
23
  from datetime import datetime, timezone
24
  from pathlib import Path
 
618
  if not KAGGLE_USERNAME or not KAGGLE_KEY:
619
  return "⚠️ KAGGLE_USERNAME / KAGGLE_KEY not set in Space secrets."
620
 
621
+ import subprocess
622
 
623
  notebooks_dir = ROOT / "notebooks"
624
  meta_file = notebooks_dir / "kernel-metadata.json"
 
629
  if not meta_file.exists():
630
  return "❌ notebooks/kernel-metadata.json not found in Space."
631
 
632
+ # Pass credentials directly as env vars (newer kaggle CLI ignores KAGGLE_CONFIG_DIR)
633
+ env = {
634
+ **os.environ,
635
+ "KAGGLE_USERNAME": KAGGLE_USERNAME,
636
+ "KAGGLE_KEY": KAGGLE_KEY,
637
+ "PYTHONUTF8": "1",
638
+ "PYTHONIOENCODING": "utf-8",
639
+ }
640
+
641
+ result = subprocess.run(
642
+ ["kaggle", "kernels", "push", "-p", str(notebooks_dir)],
643
+ capture_output=True, text=True, timeout=60, env=env,
644
+ )
 
 
 
 
 
 
 
 
 
645
 
646
  if result.returncode == 0:
647
  output = (result.stdout or "").strip()