PyGithub Programming Model: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Internal=
=Internal=
* [[Python_Package_PyGithub#Subjects|PyGithub]]
* [[Python_Package_PyGithub#Subjects|PyGithub]]
=Authentication=
=Turn on Debugging=
==Authentication with Personal Access Token (PAT)==
<syntaxhighlight lang='py'>
<syntaxhighlight lang='py'>
import os
from github import enable_console_debug_logging
from github import Github
from urllib3 import Retry


 
enable_console_debug_logging()
def access_github():
    # github = Github('user', 'password')
    github_pat = os.environ.get('GITHUB_PAT')
    if not github_pat:
        raise ValueError("'GITHUB_PAT' not setup")
    base_url = 'https://github.com'
    api_endpoint = 'api/v3'
    status_forcelist = [403, 500, 502, 504]  # retry 403s, 5XX from GitHub
    retry = Retry(total=10, backoff_factor=0.2, raise_on_status=True, status_forcelist=status_forcelist)
    github = Github(base_url=f'{base_url}/{api_endpoint}', login_or_token=github_pat, retry=retry, per_page=100)
 
    for repo in github.get_user().get_repos():
        print(repo.name)
</syntaxhighlight>
</syntaxhighlight>
=Configuring Retry=

Latest revision as of 01:50, 16 May 2023

Internal

Turn on Debugging

from github import enable_console_debug_logging

enable_console_debug_logging()