Pygithub: Github.search_topics returning list of repos that throw an error when trying to fetch undefined data

Created on 12 Oct 2018  路  6Comments  路  Source: PyGithub/PyGithub

Hello,

I was trying to fetch a list of repositories with a specific topic and then play with the returned attributes, but the Repository objects returned in the PaginatedList throw an error when trying to fetch unknown data:

Traceback (most recent call last):
  File "github-crawler.py", line 6, in <module>
    print(i, repo.archive_url)
  File "/home/user/.local/lib/python3.6/site-packages/github/Repository.py", line 2407, in get_topics
    self.url + "/topics",
  File "/home/user/.local/lib/python3.6/site-packages/github/Repository.py", line 745, in url
    self._completeIfNotSet(self._url)
  File "/home/user/.local/lib/python3.6/site-packages/github/GithubObject.py", line 259, in _completeIfNotSet
    self._completeIfNeeded()
  File "/home/user/.local/lib/python3.6/site-packages/github/GithubObject.py", line 263, in _completeIfNeeded
    self.__complete()
  File "/home/user/.local/lib/python3.6/site-packages/github/GithubObject.py", line 268, in __complete
    self._url.value
  File "/home/user/.local/lib/python3.6/site-packages/github/Requester.py", line 262, in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, self.__customConnection(url)))
  File "/home/user/.local/lib/python3.6/site-packages/github/Requester.py", line 278, in __customConnection
    if not url.startswith("/"):
AttributeError: 'NoneType' object has no attribute 'startswith'

Below is an example of the code:

from github import Github

g = Github(per_page=300)
i = 1
for repo in g.search_topics('security'):
    print(i, repo.archive_url)
    i += 1

It can be tested here: https://repl.it/repls/LawngreenPlushBetaversion

Environment:
Linux ubuntu 4.15.0-36-generic x86_64 GNU/Linux
Python 3.6.6
PyGithub 1.43.2

Any help with that ?
And thanks

Most helpful comment

PR welcome

All 6 comments

I will fix it later :p

Maybe, wrong code is here. @jacquerie

Maybe, wrong code is here. @jacquerie

Uhm? I don't think I contributed code to any of this...

Just glancing at the code. It appears that search_topics is returning a paginated list of GitHub repositories, but the API seems to return a list of topics, including the following properties:

  • name
  • display_name
  • short_description
  • description
  • created_by
  • released
  • created_at
  • updated_at
  • featured
  • curated
  • score

I think this may be the root problem.

Yes indeed, the API endpoint /search/topics returns a list of topics that are related to the provided keyword and not a list of repositories tagged with that topic (which is a little bit confusing, maybe ?).
In my code I used the other API endpoints and it worked fine.

But still, the method in PyGithub should be fixed.

PR welcome

Was this page helpful?
0 / 5 - 0 ratings