PyGithub Programming Model: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(3 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=
Various authentication mechanism are invoked by appropriately configuring the main <code>[[PyGithub_Concepts#Github|Github]]</code> class.
==Authentication with Personal Access Token (PAT)==
<syntaxhighlight lang='py'>
<syntaxhighlight lang='py'>
github_pat = os.environ.get('GITHUB_PAT')
from github import enable_console_debug_logging
if not github_pat:
    raise ValueError("'GITHUB_PAT' not found in environment")
github = Github(base_url='https://github.com/api/v3', login_or_token=github_pat)
</syntaxhighlight>


==Authentication with Username and Password==
enable_console_debug_logging()
<syntaxhighlight lang='py'>
github = Github(base_url='https://github.com/api/v3', login_or_token='someusername', password='somepassword')
</syntaxhighlight>
Note that the invocation '''does not''' fail if the username or the password is invalid. Subsequent calls are made as unauthenticated user.
 
==Authentication with JWT==
=Configuring Retry=
<syntaxhighlight lang='py'>
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='...', retry=retry, ...)
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 01:50, 16 May 2023

Internal

Turn on Debugging

from github import enable_console_debug_logging

enable_console_debug_logging()