github-release icon indicating copy to clipboard operation
github-release copied to clipboard

Setting GITHUB_TOKEN to new style GH tokens fails with 403 Client Error

Open karthiknadig opened this issue 4 years ago • 1 comments

set GITHUB_TOKEN to the new tokens that github produces which start with ghp_.

Traceback (most recent call last):
  File "C:\all_pys\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\all_pys\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\GIT\release\pvsc\.venv\Scripts\githubrelease.exe\__main__.py", line 7, in <module>
  File "c:\git\release\pvsc\.venv\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "c:\git\release\pvsc\.venv\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "c:\git\release\pvsc\.venv\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\git\release\pvsc\.venv\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\git\release\pvsc\.venv\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\git\release\pvsc\.venv\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "c:\git\release\pvsc\.venv\lib\site-packages\click\decorators.py", line 33, in new_func
    return f(get_current_context().obj, *args, **kwargs)
  File "c:\git\release\pvsc\.venv\lib\site-packages\github_release.py", line 437, in cli_release_create
    gh_release_create(*args, **kwargs)
  File "c:\git\release\pvsc\.venv\lib\site-packages\github_release.py", line 116, in with_check_for_credentials
    return func(*args, **kwargs)
  File "c:\git\release\pvsc\.venv\lib\site-packages\github_release.py", line 444, in gh_release_create
    if get_release(repo_name, tag_name) is not None:
  File "c:\git\release\pvsc\.venv\lib\site-packages\github_release.py", line 259, in get_release
    releases = get_releases(repo_name)
  File "c:\git\release\pvsc\.venv\lib\site-packages\github_release.py", line 249, in get_releases
    _recursive_gh_get(
  File "c:\git\release\pvsc\.venv\lib\site-packages\github_release.py", line 155, in _recursive_gh_get
    response.raise_for_status()
  File "c:\git\release\pvsc\.venv\lib\site-packages\requests\models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.github.com/repos

Same command works with old style GH tokens. GH is asking repos to upgrade to new style tokens.

karthiknadig avatar Sep 20 '21 19:09 karthiknadig

Since the basic authentication is not supported anymore, the authentication should be updated to work with new style token by setting header like Authorization: token ghp_123...456

This means the following code should be updated:

https://github.com/j0057/github-release/blob/067d7f1f557e16c4db57696d30732d566e314a45/github_release.py#L74-L78

If a token doesn't start with ghp_, an error should be reported suggesting the user to create a new style token

For reference, see https://docs.github.com/en/rest/overview/troubleshooting#basic-authentication-errors

jcfr avatar Dec 22 '21 05:12 jcfr