PyGithub / PyGithub/PyGithub

System and Github server time difference is causing 401

Open
#3,092 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.8k
Forks
1.9k
Avg merge
17m
Merged PRs (30d)
2

Description

During execution when PyGithub needs to refresh token it ran into problem. It was running smoothly before but at that moment started giving 401 errors. What appears to be the reason for this is caused by difference between time of local system and github servers. This error came around midnight local time. Generally it is not observed but for long running processes it might be critical.

Stack trace:

File "/usr/local/lib/python3.11/site-packages/github/Requester.py", line 548, in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, self.__customConnection(url)))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/github/Requester.py", line 713, in requestJson
    return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/github/Requester.py", line 798, in __requestEncode
    requestHeaders["Authorization"] = f"{self.__auth.token_type} {self.__auth.token}"
                                                                  ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/github/Auth.py", line 328, in token
    self.__installation_authorization = self._get_installation_authorization()
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/github/Auth.py", line 339, in _get_installation_authorization
    return self.__integration.get_access_token(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/github/GithubIntegration.py", line 228, in get_access_token
    headers, response = self.__requester.requestJsonAndCheck(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/github/Requester.py", line 548, in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, self.__customConnection(url)))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/github/Requester.py", line 609, in __check
    raise self.createException(status, responseHeaders, data)
github.GithubException.GithubException: 401 {"message": "'Expiration time' claim ('exp') must be a numeric value representing the future time at which the assertion expires", "documentation_url": "https://docs.github.com/rest", "status": "401"}

A relevant issue issue was resolved here - https://github.com/octokit/auth-app.js/pull/164

The approach identifies the time diff b/w servers and adjust exp/iat accordingly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Auth.py, especially _get_installation_authorization and token, then follow the request through GithubIntegration.py's get_access_token. Compare the reported expiration and issued-at handling with the linked octokit/auth-app.js pull request. Done means long-running token refreshes account for the GitHub server time difference and no longer fail with the reported 401 expiration error.

Written by the indexing model from the issue text.

Assessment

Tech stack
github, python
Domain
api, authentication
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.