mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-08-30 19:15:56 +02:00
[devscripts/create-github-release] Switch to using PAT for authentication
Basic authentication will be deprecated soon
This commit is contained in:
parent
d6bf9cbd46
commit
0d5c415e1f
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
from youtube_dl.compat import (
|
from youtube_dl.compat import (
|
||||||
compat_basestring,
|
compat_basestring,
|
||||||
compat_input,
|
|
||||||
compat_getpass,
|
compat_getpass,
|
||||||
compat_print,
|
compat_print,
|
||||||
compat_urllib_request,
|
compat_urllib_request,
|
||||||
@ -40,28 +39,20 @@ def _init_github_account(self):
|
|||||||
try:
|
try:
|
||||||
info = netrc.netrc().authenticators(self._NETRC_MACHINE)
|
info = netrc.netrc().authenticators(self._NETRC_MACHINE)
|
||||||
if info is not None:
|
if info is not None:
|
||||||
self._username = info[0]
|
self._token = info[2]
|
||||||
self._password = info[2]
|
|
||||||
compat_print('Using GitHub credentials found in .netrc...')
|
compat_print('Using GitHub credentials found in .netrc...')
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
compat_print('No GitHub credentials found in .netrc')
|
compat_print('No GitHub credentials found in .netrc')
|
||||||
except (IOError, netrc.NetrcParseError):
|
except (IOError, netrc.NetrcParseError):
|
||||||
compat_print('Unable to parse .netrc')
|
compat_print('Unable to parse .netrc')
|
||||||
self._username = compat_input(
|
self._token = compat_getpass(
|
||||||
'Type your GitHub username or email address and press [Return]: ')
|
'Type your GitHub PAT (personal access token) and press [Return]: ')
|
||||||
self._password = compat_getpass(
|
|
||||||
'Type your GitHub password and press [Return]: ')
|
|
||||||
|
|
||||||
def _call(self, req):
|
def _call(self, req):
|
||||||
if isinstance(req, compat_basestring):
|
if isinstance(req, compat_basestring):
|
||||||
req = sanitized_Request(req)
|
req = sanitized_Request(req)
|
||||||
# Authorizing manually since GitHub does not response with 401 with
|
req.add_header('Authorization', 'token %s' % self._token)
|
||||||
# WWW-Authenticate header set (see
|
|
||||||
# https://developer.github.com/v3/#basic-authentication)
|
|
||||||
b64 = base64.b64encode(
|
|
||||||
('%s:%s' % (self._username, self._password)).encode('utf-8')).decode('ascii')
|
|
||||||
req.add_header('Authorization', 'Basic %s' % b64)
|
|
||||||
response = self._opener.open(req).read().decode('utf-8')
|
response = self._opener.open(req).read().decode('utf-8')
|
||||||
return json.loads(response)
|
return json.loads(response)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user