commaai/openpilot · error · Exception
Call to {path} failed with {r.status_code}
Error message
Call to {path} failed with {r.status_code} What it means
github_utils api_call() wraps requests.request; when the GitHub API (or the configured data route) returns a non-OK status and raise_on_failure is True (default), it raises a bare Exception with the path and status code. Common statuses: 401 bad/expired token, 403 rate limit, 404 missing repo/file, 422 validation.
Source
Thrown at openpilot/tools/lib/github_utils.py:31
@property
def API_ROUTE(self):
return f"https://api.github.com/repos/{self.OWNER}/{self.API_REPO}"
@property
def DATA_ROUTE(self):
return f"https://api.github.com/repos/{self.OWNER}/{self.DATA_REPO}"
def api_call(self, path, data="", method=HTTPMethod.GET, accept="", data_call=False, raise_on_failure=True):
token = self.DATA_TOKEN if data_call else self.API_TOKEN
if token:
headers = {"Authorization": f"Bearer {self.DATA_TOKEN if data_call else self.API_TOKEN}", \
"Accept": f"application/vnd.github{accept}+json"}
else:
headers = {}
path = f'{self.DATA_ROUTE if data_call else self.API_ROUTE}/{path}'
r = requests.request(method, path, headers=headers, data=data)
if not r.ok and raise_on_failure:
raise Exception(f"Call to {path} failed with {r.status_code}")
else:
return r
def upload_file(self, bucket, path, file_name):
with open(path, "rb") as f:
encoded = base64.b64encode(f.read()).decode()
# check if file already exists
sha = self.get_file_sha(bucket, file_name)
sha = f'"sha":"{sha}",' if sha else ''
data = f'{{"message":"uploading {file_name}", \
"branch":"{bucket}", \
"committer":{{"name":"Vehicle Researcher", "email": "user@comma.ai"}}, \
{sha} \
"content":"{encoded}"}}'
github_path = f"contents/{file_name}"
self.api_call(github_path, data=data, method=HTTPMethod.PUT, data_call=True)View on GitHub (pinned to 516ec1e682)
Solutions
- Check the status code in the message: 401/403 => fix the token (GITHUB_TOKEN env / auth config), 403 with 'rate limit' => wait or authenticate, 404 => verify repo name/path
- Test the token: curl -H "Authorization: Bearer $TOKEN" https://api.github.com/user
- Pass raise_on_failure=False if you want to handle the response yourself instead of an exception
Example fix
# before
api.api_call(f'contents/{bucket}/{file_name}', data=data, method=HTTPMethod.PUT)
# after
r = api.api_call(f'contents/{bucket}/{file_name}', data=data, method=HTTPMethod.PUT, raise_on_failure=False)
if r.status_code in (403, 429):
time.sleep(int(r.headers.get('X-RateLimit-Reset', time.time() + 60)) - time.time())
r = api.api_call(f'contents/{bucket}/{file_name}', data=data, method=HTTPMethod.PUT) Defensive patterns
Strategy: retry
Validate before calling
def token_valid(token: str) -> bool:
r = requests.get('https://api.github.com/user', headers={'Authorization': f'Bearer {token}'})
return r.status_code == 200 Try / catch
r = api.api_call(path, raise_on_failure=False)
if r.status_code == 403 and 'rate limit' in r.text:
wait_for_rate_limit_reset(r)
r = api.api_call(path)
r.raise_for_status() Prevention
- Check token validity once at job start, not per-call
- Handle 403 rate limits by sleeping until X-RateLimit-Reset
- Use raise_on_failure=False when you want status-based logic instead of exceptions
When it happens
Trigger: Any api_call()/upload_file()/get_file_sha() on the github data repo — uploading route data with an invalid GITHUB_TOKEN, hitting the hourly rate limit, or referencing a repo the token cannot see.
Common situations: Expired personal access token; un-set token in CI hitting 401/403 rate limits; wrong OWNER/DATA_REPO config; pushing a file larger than GitHub allows.
Related errors
- unable to get max_segment_number. ensure you have access to
- {error_prefix} failed: {reason}/{subject} - {sd.get('message
- Maximum retries exceeded
- {func.__name__} failed after retry
- error getting events for segment {self._name}
AI-assisted analysis of commaai/openpilot@516ec1e682 (2026-08-15).
Data as JSON: /api/errors/cf49cb76923edfe5.
Report an issue: GitHub.