0

Everything goes smoothly until I invoke create_repo on AuthenticatedUser from get_user(). No matter what I try it always throws an exception:

[ERROR tornado.application web:1599] Exception in exception handler Traceback (most recent call last):   File "/Users/marcocano/Desktop/tsri/discovery-app/discovery/web/api/github.py", line 43, in post
    repo = auth_user.create_repo(repo_name)   File "/Users/marcocano/Desktop/tsri/discovery-app/env/lib/python3.6/site-packages/github/AuthenticatedUser.py", line 679, in create_repo
    "POST", "/user/repos", input=post_parameters   File "/Users/marcocano/Desktop/tsri/discovery-app/env/lib/python3.6/site-packages/github/Requester.py", line 319, in requestJsonAndCheck
    verb, url, parameters, headers, input, self.__customConnection(url)   File "/Users/marcocano/Desktop/tsri/discovery-app/env/lib/python3.6/site-packages/github/Requester.py", line 342, in __check
    raise self.__createException(status, responseHeaders, output) github.GithubException.UnknownObjectException: 404 {"message": "Not Found", "documentation_url": "https://docs.github.com/rest/reference/repos#create-a-repository-for-the-authenticated-user"}

Code:

 if self.request.headers['Content-Type'] == 'application/json':
                self.args = json.loads(self.request.body)
            repo_name = self.args.get('name', None)
            if not repo_name:
                raise HTTPError(400, reason=f"Required parameter 'name' not provided")

        user = json.loads(self.get_secure_cookie("user"))
        # signin with token
        g = Github(user['access_token'])
        # authenticated user
        auth_user = g.get_user()
        if auth_user.login:
            try:
                print('auth_user',auth_user)
                repo = auth_user.create_repo(repo_name)
                print(repo)
            except GithubException as e:
                raise HTTPError(400, reason=e)
            except Exception as exc:  # unexpected
                raise HTTPError(500, reason=str(exc))

        else:
            raise HTTPError(400, reason=f"Unable to authenticate user")

        return repo
Marco Cano
  • 367
  • 1
  • 4
  • 18
  • this is the docs one of the errors leads me to but that should be handled internally by the package https://docs.github.com/en/rest/reference/repos#create-a-repository-for-the-authenticated-user – Marco Cano Sep 23 '20 at 00:07

1 Answers1

0

The issue is the token I was given lacked the proper scopes, here is the docs for requesting correct scopes: https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/

Marco Cano
  • 367
  • 1
  • 4
  • 18