sigmavirus24 / github3.py

Hi, I'm a library for interacting with GItHub's REST API in a convenient and ergonomic way. I work on Python 3.6+.
https://github3.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.2k stars 401 forks source link

Unable to fetch License for a repository #595

Closed Ianleeclark closed 8 years ago

Ianleeclark commented 8 years ago

Hello!

Using github3.py==1.0.0a4 and Python 2.7.10

I have a really strange issue, where I'm unable to fetch a license upon github3.repository() with one repository, but the same credentials work for another repository.

Here's the code sample that I'm using to login() and to call the .repository() method with:

class GithubHandler(object):
    """
    The main handler for any and all interactions with Github.
    """

    def __init__(self, user, token, owner, repo):
        self.is_authed = False

        # Auth stuff
        self.user = user
        self.token = token
        self.gh = self.login()
        self.repo_name = repo
        self.curr_repo = self.gh.repository(owner, repo)

    def login(self):
        try:
            return github3.login(token=self.token)
        except github3.models.GitHubError:
            raise

Nothing too fancy, just what I thought would be boiler plate.

What I call it with:

    git = GithubHandler('GrappigPanda',
                        '<super-secret-token>',
                        'GrappigPanda',
                        'notorious')

The GrappigPanda/notorious repo causes it to fail, but if I am to run it on GrappigPanda/pygemony, everything is copacetic.

Both of these repos have Licenses (same name format "LICENSE", and I most likely copy pasted the LICENSE from pygemony to notorious).

Here's a link to notorious' license, just to show something weird is happening here: https://github.com/GrappigPanda/notorious/blob/master/LICENSE

Now, with all that said, I do want to note this: ever since inception of the notorious repo, I've had several strange issues with it (some of which required contacting Github support), so there's entirely the possibility that there's just mangled data or some other such thing on Github's end. Albeit, I'm not 100% sure how to investigate if it is on Github's end, but I'm going to try curling endpoints and seeing if I can get anything weird. If everything seems normal, I'll follow up here.

Ianleeclark commented 8 years ago

There's entirely the possibility that I'm just way too sleepy, but I'm able to curl the license:

sh-3.2$ curl -X GET https://api.github.com/repos/GrappigPanda/notorious/contents/. | grep LICENSE
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 11720  100 11720    0     0  32197      0 --:--:-- --:--:-- --:--:-- 32286
    "name": "LICENSE",
    "path": "LICENSE",
    "url": "https://api.github.com/repos/GrappigPanda/notorious/contents/LICENSE?ref=master",
    "html_url": "https://github.com/GrappigPanda/notorious/blob/master/LICENSE",
    "download_url": "https://raw.githubusercontent.com/GrappigPanda/notorious/master/LICENSE",
      "self": "https://api.github.com/repos/GrappigPanda/notorious/contents/LICENSE?ref=master",
      "html": "https://github.com/GrappigPanda/notorious/blob/master/LICENSE"
sigmavirus24 commented 8 years ago

Could you provide:

Thanks,

Ianleeclark commented 8 years ago

Hi other Ian C,

I never explicitly attempt to access the license, it seems to be part of the repository() method. The code where I try to access the license is the code provided and will fail on the line with self.curr_repo = self.gh.repository

I don't have the traceback available, so I can't copy paste it (being driven home right now, sorry, but I'll provide it later). However, the gist of the issue is that license is None, so attempting to call the get method for the dictionary member "url" fails. That shouldn't be a keyerror because the License object is type none, so that should be an Attributeerror.

Sorry for any spelling errors and most importantly not providing the traceback last night, but I'll update this issue later.

Thanks, Ian. On Apr 3, 2016 13:27, "Ian Cordasco" notifications@github.com wrote:

Could you provide:

  • the code where you attempt to access the license
  • the error/exception you see (or define what failure is)

Thanks,

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/sigmavirus24/github3.py/issues/595#issuecomment-205025812

sigmavirus24 commented 8 years ago

Sorry for any spelling errors and most importantly not providing the traceback last night

No worries :)

The spelling errors I didn't notice (if they're there).

Ianleeclark commented 8 years ago

And another thing to note, I'm actually running github3.py version 1.0.0a4. I thought it was the version in my virtualenvironment, but apparently I wasn't running this in my venv last night.

All right, so here's the traceback:

Traceback (most recent call last):
  File "app.py", line 19, in <module>
    'notorious')
  File "/Users/ianclark/PycharmProjects/Goggles/goggles/goggles.py", line 19, in __init__
    self.curr_repo = self.gh.repository('GrappigPanda','notorious')
  File "/Library/Python/2.7/site-packages/github3/github.py", line 1140, in repository
    return self._instance_or_null(Repository, json)
  File "/Library/Python/2.7/site-packages/github3/models.py", line 148, in _instance_or_null
    return instance_class(json, self)
  File "/Library/Python/2.7/site-packages/github3/models.py", line 51, in __init__
    self._update_attributes(json)
  File "/Library/Python/2.7/site-packages/github3/repos/repo.py", line 120, in _update_attributes
    self.original_license = License(repo.get('license', {}), self)
  File "/Library/Python/2.7/site-packages/github3/models.py", line 51, in __init__
    self._update_attributes(json)
  File "/Library/Python/2.7/site-packages/github3/licenses.py", line 22, in _update_attributes
    self._api = license.get('url', '')
AttributeError: 'NoneType' object has no attribute 'get'

But as stated, if I try it with the repository GrappigPanda/pygemony, everything works.

itsmemattchung commented 8 years ago

I'm currently not able to reproduce with the repository GrappigPanda/notorious:

import github3
import os

token = os.environ.get('GH_AUTH')
gh = github3.GitHub(token=token)
repo = gh.repository('GrappigPanda','notorious')
print repo
$ python issue_595.py 
GrappigPanda/notorious

Did anything change with the repository recently?

Ianleeclark commented 8 years ago

Hi @itsmemattchung, besides a push or two, nothing has changed.

However, are you running github3.py==0.9.5? I updated a few posts ago, but maybe you didn't see it: I was actually running 1.0.0a4 whenever I encountered this issue. I updated it in the initial issue message

sigmavirus24 commented 8 years ago

@GrappigPanda it looks like you installed from git. In 1.0.0a4, L22 does not have license.get('url'). That's something that appeared more recently. That was also fixed with https://github.com/sigmavirus24/github3.py/pull/593

Can you either install 1.0.0a4 from PyPI or re-install from git?

Ianleeclark commented 8 years ago

@sigmavirus24 Yeah, that's it 100%. I managed to install 1.0.0a4 from pypi and it works (no idea when I installed from github, but I've been known to do stranger things). It's kind of weird, though because the repository has a license for sure (https://github.com/GrappigPanda/notorious/blob/master/LICENSE) and the license is persistent regardless of branch--I was even able to request it with curl Regardless, thank you both for your help and I'm going to close this issue.