我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用github.RateLimitExceededException()。
def testRateLimitExceeded(self): g = github.Github() def exceed(): for i in range(100): g.get_user("jacquev6") self.assertRaises(github.RateLimitExceededException, exceed)
def index(request: HttpRequest) -> HttpResponse: uploaded_file = request.FILES.get('file') url = request.POST['repo-url'] if 'repo-url' in request.POST else None mode = request.POST['mode'] if 'mode' in request.POST else None if mode and uploaded_file: data = uploaded_file.read() text = data.decode(uploaded_file.charset or 'utf-8') else: text = None output_lines = '' reports = None validation_output = None probabilities = [] try: if mode == 'train': output_lines, reports = classifier.train(text) if text else ([], None) elif mode == 'classify': output_lines = classifier.classify(text) if text else None elif mode == 'classify-single-repo': probabilities = classifier.classify_single_repo(url.rstrip('/')) if url else [] elif mode == 'validate': validation_output = classifier.validate(text) if text else None except RateLimitExceededException: output_lines = 'The available request limit was exceeded for the Github API please wait until refresh.' context = { 'output': output_lines, 'validation_output': validation_output, 'single_repository': url, 'probabilities': probabilities, 'reports': reports, } return render(request, 'classification/index.html', context)
def event_handler(event_type, data): """Everything start here""" integration = github.GithubIntegration(config.INTEGRATION_ID, config.PRIVATE_KEY) token = integration.get_access_token(data["installation"]["id"]).token g = github.Github(token) try: user = g.get_user(data["repository"]["owner"]["login"]) repo = user.get_repo(data["repository"]["name"]) engine.PastaMakerEngine(g, user, repo).handle(event_type, data) except github.RateLimitExceededException: LOG.error("rate limit reached")
def get_github_organization_plugins(self, organization, no_forks=False): """ Returns a dict with all plugins from a GitHub organization inspired from: https://gist.github.com/ralphbean/5733076 :param organization: GitHub organization name :param no_forks: include / not include forks """ plugins_dict = OrderedDict() try: gh = github.Github() all_repos = gh.get_organization(organization).get_repos() except github.RateLimitExceededException: raise IRException("Github API rate limit exceeded") for repo in all_repos: try: # Don't print the urls for repos that are forks. if no_forks and repo.fork: continue spec_file = repo.get_contents('plugin.spec').decoded_content plugin = SpecValidator.validate_from_content(spec_file) plugin_name = plugin["subparsers"].keys()[0] plugin_src = repo.clone_url plugin_type = plugin["config"]["plugin_type"] \ if "config" in plugin \ else plugin["plugin_type"] plugin_desc = plugin["description"] \ if "description" in plugin \ and plugin["description"] is not None \ else "-" if plugin_type not in plugins_dict: plugins_dict[plugin_type] = {} plugins_dict[plugin_type][plugin_name] = { "src": plugin_src, "desc": plugin_desc, } except github.RateLimitExceededException: raise IRException("Github API rate limit exceeded") except Exception: # skip repo failures continue return plugins_dict