Last active
June 10, 2016 20:05
-
-
Save jfach/ec85c6550cf9fc99e3a708bd45ec6a8c to your computer and use it in GitHub Desktop.
generate PAT for github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GITHUB_API = 'https://api.github.com' | |
import requests | |
import getpass | |
import json | |
from urlparse import urljoin | |
def main(): | |
# | |
# User Input | |
# | |
username = raw_input('github username: ') | |
password = getpass.getpass('github password: ') | |
note = raw_input('Label: ') # DONT LEAVE THIS FIELD BLANK!!! | |
# | |
# Compose Request | |
# | |
url = urljoin(GITHUB_API, 'authorizations') | |
payload = {} | |
if note: | |
payload['note'] = note | |
res = requests.post( | |
url, | |
auth = (username, password), | |
data = json.dumps(payload), | |
) | |
# | |
# Parse Response | |
# | |
j = json.loads(res.text) | |
token = j['token'] | |
print token | |
return token | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Garysoccer