REST API /repos/{owner}/{repo}/actions/runs/{run_id}/attempts/{attempt_number}/logs returns 404 while workflow run is still running #75518
Replies: 229 comments 7 replies
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
👍 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
Any update ? |
BetaWas this translation helpful?Give feedback.
-
hallo |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
Yeah, this is expected behavior. The logs API usually returns a 404 while the workflow or job is still running — logs are only available once the run is complete. Would be great if GitHub supported partial or live logs, but as of now, we just have to wait for it to finish. |
BetaWas this translation helpful?Give feedback.
-
This is a timing issue with the GitHub Actions API. The logs endpoint returns 404 because logs aren't immediately available during workflow execution. Here's the solution: Root Cause
Solution 1: Wait for Completion# Poll until workflow completeswhiletrue;do status=$(curl -s -H "Authorization: token $TOKEN" \"https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID"| \ jq -r '.status')if [[ "$status"=="completed" ]];then# Now logs are available curl -H "Authorization: token $TOKEN" \ "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID/attempts/1/logs"breakfiecho"Status: $status, waiting..." sleep 30 doneSolution 2: Use Job-Level Logs (More Reliable)Get individual job logs instead of run logs# 1. Get jobs for the run curl -H "Authorization: token $TOKEN" \ "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID/jobs"| \ jq -r '.jobs[].id'# 2. Get logs for specific job (works during execution) curl -H "Authorization: token $TOKEN" \ "https://api.github.com/repos/$OWNER/$REPO/actions/jobs/$JOB_ID/logs"Solution 3: Real-Time Streaming (Advanced)importrequestsimporttimedefstream_workflow_logs(owner, repo, run_id, token): headers={"Authorization": f"token {token}"} whileTrue: # Check run statusrun_response=requests.get( f"https://api.github.com/repos/{owner}/{repo}/actions/runs/{run_id}", headers=headers ) ifrun_response.json()["status"] =="completed": # Get final logslogs_response=requests.get( f"https://api.github.com/repos/{owner}/{repo}/actions/runs/{run_id}/logs", headers=headers ) returnlogs_response.content# Get job logs during executionjobs_response=requests.get( f"https://api.github.com/repos/{owner}/{repo}/actions/runs/{run_id}/jobs", headers=headers ) forjobinjobs_response.json()["jobs"]: ifjob["status"] in ["in_progress", "completed"]: job_logs=requests.get( f"https://api.github.com/repos/{owner}/{repo}/actions/jobs/{job['id']}/logs", headers=headers ) ifjob_logs.status_code==200: print(f"Job {job['name']} logs available") time.sleep(10)Solution 4: GitHub CLI Alternative# Real-time log following gh run view $RUN_ID --log # Or watch specific job gh run view $RUN_ID --job=$JOB_ID --logAPI Behavior Summary
Workaround for Your Use Case# Robust script that handles the timing issueget_workflow_logs(){local run_id=$1local max_attempts=60 # 30 minutes max waitlocal attempt=0 while [ $attempt-lt$max_attempts ];do# Try the run logs endpointif curl -sf -H "Authorization: token $TOKEN" \ "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id/logs" \ -o "logs_$run_id.zip";thenecho"Logs downloaded successfully"return 0 fi# Fall back to job logs if run logs not ready curl -s -H "Authorization: token $TOKEN" \ "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id/jobs"| \ jq -r '.jobs[].id'|whileread job_id;do curl -s -H "Authorization: token $TOKEN" \ "https://api.github.com/repos/$OWNER/$REPO/actions/jobs/$job_id/logs" \ >>"partial_logs_$run_id.txt"done sleep 30 ((attempt++))done }The 404 is expected behavior - you need to handle the timing appropriately. |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
UP |
BetaWas this translation helpful?Give feedback.
-
Yes please, we need this. 👍 |
BetaWas this translation helpful?Give feedback.
-
up |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
-
+1 |
BetaWas this translation helpful?Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Bug
Body
It is impossible to receive the logs of a workflow-run that is in-progress because of that reason.
Also using https://api.github.com/repos/OWNER/REPO/actions/jobs/JOB_ID/logs for getting a specific job logs it returns 404 while the job is running.
BetaWas this translation helpful?Give feedback.
All reactions