mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-02 03:41:08 +00:00
#664 got rid of most of httplib and replaced it with requests. This is the last place it was used. It makes a more coherent code base I think. Tests are ok locally.
This commit is contained in:
committed by
Wan Liuyang
parent
1c0fd97d7d
commit
cd6d56d60a
+15
-21
@@ -53,7 +53,7 @@ import urllib
|
||||
import pickle
|
||||
import time
|
||||
import sys
|
||||
from httplib import HTTPSConnection
|
||||
import requests
|
||||
import jwt
|
||||
|
||||
from Requester import Requester, json
|
||||
@@ -775,25 +775,19 @@ class GithubIntegration(object):
|
||||
body = None
|
||||
if user_id:
|
||||
body = json.dumps({"user_id": user_id})
|
||||
conn = HTTPSConnection("api.github.com")
|
||||
conn.request(
|
||||
method="POST",
|
||||
url="/installations/{}/access_tokens".format(installation_id),
|
||||
headers={
|
||||
"Authorization": "Bearer {}".format(self.create_jwt()),
|
||||
"Accept": Consts.mediaTypeIntegrationPreview,
|
||||
"User-Agent": "PyGithub/Python"
|
||||
},
|
||||
body=body
|
||||
)
|
||||
response = conn.getresponse()
|
||||
response_text = response.read()
|
||||
response = requests.post("https://api.github.com/installations/{}/access_tokens".format(installation_id),
|
||||
headers={
|
||||
"Authorization": "Bearer {}".format(self.create_jwt()),
|
||||
"Accept": Consts.mediaTypeIntegrationPreview,
|
||||
"User-Agent": "PyGithub/Python"
|
||||
},
|
||||
body=body)
|
||||
response_text = response.text
|
||||
|
||||
if atLeastPython3:
|
||||
response_text = response_text.decode('utf-8')
|
||||
|
||||
conn.close()
|
||||
if response.status == 201:
|
||||
if response.status_code == 201:
|
||||
data = json.loads(response_text)
|
||||
return InstallationAuthorization.InstallationAuthorization(
|
||||
requester=None, # not required, this is a NonCompletableGithubObject
|
||||
@@ -801,17 +795,17 @@ class GithubIntegration(object):
|
||||
attributes=data,
|
||||
completed=True
|
||||
)
|
||||
elif response.status == 403:
|
||||
elif response.status_code == 403:
|
||||
raise GithubException.BadCredentialsException(
|
||||
status=response.status,
|
||||
status=response.status_code,
|
||||
data=response_text
|
||||
)
|
||||
elif response.status == 404:
|
||||
elif response.status_code == 404:
|
||||
raise GithubException.UnknownObjectException(
|
||||
status=response.status,
|
||||
status=response.status_code,
|
||||
data=response_text
|
||||
)
|
||||
raise GithubException.GithubException(
|
||||
status=response.status,
|
||||
status=response.status_code,
|
||||
data=response_text
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user