refine: colab tunnel cell - skip poll when cloudflared missing, softer verify message
Reviewer feedback: guard the 120s URL poll with shutil.which(cloudflared) so the failure case returns immediately; merge import re into the cell top import; note Cloudflare browser-check interstitials can fail urllib verification even when the link works in a real browser.
This commit is contained in:
@@ -214,7 +214,7 @@ def cells() -> list[dict]:
|
||||
"# 10) 서버 기동 (in-proc 큐, 백그라운드 — nohup)\n"
|
||||
"# 이전 실행에서 남은 서버가 포트 8000을 점유하면 새 키를 모른 채 401이 난다.\n"
|
||||
"# → 먼저 기존 서버를 모두 종료하고, 키 파일 경로를 명시해 재시작한다.\n"
|
||||
"import subprocess, os, time, urllib.request, urllib.error\n"
|
||||
"import subprocess, os, re, shutil, time, urllib.request, urllib.error\n"
|
||||
"\n"
|
||||
"assert 'RAW_KEY' in globals(), '셀 9(키 생성)를 먼저 실행하세요'\n"
|
||||
"\n"
|
||||
@@ -256,15 +256,17 @@ def cells() -> list[dict]:
|
||||
" raise SystemExit('키 인증 실패 — RAW_KEY 캡처/키 파일 확인')\n"
|
||||
"\n"
|
||||
"# ── Cloudflare 터널 URL 캡처 + 외부 접속 검증 (서버 로그의 trycloudflare URL) ──\n"
|
||||
"import re\n"
|
||||
"TUNNEL_URL = None\n"
|
||||
"for _ in range(60):\n"
|
||||
" log = open('/content/logs/server.log', encoding='utf-8', errors='replace').read()\n"
|
||||
" m = re.search(r'https://[a-z0-9-]+\\.trycloudflare\\.com', log)\n"
|
||||
" if m:\n"
|
||||
" TUNNEL_URL = m.group(0)\n"
|
||||
" break\n"
|
||||
" time.sleep(2)\n"
|
||||
"if shutil.which('cloudflared'):\n"
|
||||
" for _ in range(60):\n"
|
||||
" log = open('/content/logs/server.log', encoding='utf-8', errors='replace').read()\n"
|
||||
" m = re.search(r'https://[a-z0-9-]+\\.trycloudflare\\.com', log)\n"
|
||||
" if m:\n"
|
||||
" TUNNEL_URL = m.group(0)\n"
|
||||
" break\n"
|
||||
" time.sleep(2)\n"
|
||||
"else:\n"
|
||||
" print('cloudflared 미설치 (셀 3 다운로드 실패) — 터널 생략, 로컬(8000) 계속 사용')\n"
|
||||
"\n"
|
||||
"if TUNNEL_URL:\n"
|
||||
" print('🌐 Cloudflare 터널 (외부 접속):', TUNNEL_URL)\n"
|
||||
@@ -274,10 +276,10 @@ def cells() -> list[dict]:
|
||||
" ext = urllib.request.urlopen(TUNNEL_URL + '/health', timeout=15)\n"
|
||||
" print(' 외부 접속 검증 OK (HTTP', ext.status, ')')\n"
|
||||
" except Exception as exc:\n"
|
||||
" print(' 외부 접속 검증 실패:', exc)\n"
|
||||
" print(' 외부 접속 검증 실패 (브라우저에선 열릴 수 있음):', exc)\n"
|
||||
" print(' ※ 임시 링크 — Colab 세션 종료 시 닫힘. API 호출에는 RAW_KEY(X-API-Key) 필요.')\n"
|
||||
"else:\n"
|
||||
" print('터널 URL 미감지 (cloudflared 미설치/연결 실패) — 서버 로그:')\n"
|
||||
" print('터널 URL 미감지 — 서버 로그:')\n"
|
||||
" print(open('/content/logs/server.log').read()[-1200:])\n"
|
||||
" print('로컬(8000)에서 계속 사용할 수 있습니다.')\n"
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user