我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用github.BadCredentialsException()。
def get(self, request, *args, **kwargs): g = get_github(self.request.user) try: repos = [r for r in g.get_user().get_repos()] except BadCredentialsException: UserSocialAuth.objects.filter(user=request.user).delete() return redirect(reverse('social:begin', args=['github'])) + '?next=' + request.path self.object_list = Repo.objects.filter( full_name__in=[i.full_name for i in repos], disabled=False ).annotate(builds_count=Count('builds')) names = [x.full_name for x in self.object_list] filtered = [] for repo in repos: if repo.full_name not in names: filtered.append(repo) context = self.get_context_data() context['repos'] = filtered context['welcome'] = request.GET.get('welcome', False) return self.render_to_response(context)
def testBadCredentials(self): self.assertRaises(github.BadCredentialsException, lambda: github.Github("BadUser", "BadPassword").get_user().login)
def login(self, username, pwd): try: self.gh = Github(username, pwd) # This expression has no effect but will throw an exception if the authentication failed. self.gh.get_user().id self.ghapi = self.gh.get_repo(self.repository) return True except BadCredentialsException: return False