Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking github.Auth.AppInstallationAuth expiry raises timezone-related error #2560

Closed
antoineKorbit opened this issue Jun 20, 2023 · 2 comments · Fixed by #2561
Closed

Checking github.Auth.AppInstallationAuth expiry raises timezone-related error #2560

antoineKorbit opened this issue Jun 20, 2023 · 2 comments · Fixed by #2561

Comments

@antoineKorbit
Copy link

I'm currently running the master branch in order to test the PR#2540 locally, and I'm getting an exception due to expired token when it's definitely not.

Here is the context and what I do to reproduce:

  1. I have a Github application bot that I connect to using the following code:
    gh_app_auth = github.Auth.AppAuth(
        app_id=get_github_app_id(), private_key=get_private_key(), jwt_expiry=600
    )
    gh_app = github.Auth.AppInstallationAuth(
        app_auth=gh_app_auth,
        installation_id=int(installation_id),
    )
    
    rest_github = github.Github(
        auth=gh_app,
    )
  2. When I try to get a repository with rest_github.get_repo(repository_name) it works the first time.
  3. But if I run the same function again, I will get the following exception:
    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/opt/miniconda3/envs/my_env/lib/python3.11/site-packages/github/MainClass.py", line 360, in get_repo
        headers, data = self.__requester.requestJsonAndCheck("GET", url)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/opt/miniconda3/envs/my_env/lib/python3.11/site-packages/github/Requester.py", line 431, in requestJsonAndCheck
        *self.requestJson(
        ^^^^^^^^^^^^^^^^^
    File "/opt/miniconda3/envs/my_env/lib/python3.11/site-packages/github/Requester.py", line 568, in requestJson
        return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/opt/miniconda3/envs/my_env/lib/python3.11/site-packages/github/Requester.py", line 661, in __requestEncode
        ] = f"{self.__auth.token_type} {self.__auth.token}"
                                        ^^^^^^^^^^^^^^^^^
    File "/opt/miniconda3/envs/my_env/lib/python3.11/site-packages/github/Auth.py", line 299, in token
        if self.__installation_authorization is None or self._is_expired:
                                                        ^^^^^^^^^^^^^^^^
    File "/opt/miniconda3/envs/my_env/lib/python3.11/site-packages/github/Auth.py", line 310, in _is_expired
        return token_expires_at < datetime.now(timezone.utc)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: can't compare offset-naive and offset-aware datetimes
    

I have set the jwt_expiry value to 600s, but it doesn't take it into consideration.
Would anyone have a suggestion ?

@EnricoMi
Copy link
Collaborator

Thanks for reporting, this is definitively a bug that has sneaked in recently. I'm looking into this before releasing this.

@EnricoMi EnricoMi changed the title github.Auth.AppAuth jwt instantly expery Checking github.Auth.AppInstallationAuth expiry raises timezone-related error Jun 20, 2023
@EnricoMi
Copy link
Collaborator

EnricoMi commented Jun 20, 2023

Thanks for testing master, exiting tests have not been able to uncover this. Fix is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants