diff --git a/bugwarrior/services/github.py b/bugwarrior/services/github.py index 617b7cd43..c7a750696 100644 --- a/bugwarrior/services/github.py +++ b/bugwarrior/services/github.py @@ -12,6 +12,10 @@ class GithubClient(ServiceClient): def __init__(self, auth): self.auth = auth + self.session = requests.Session() + if 'token' in self.auth: + authorization = 'token ' + self.auth['token'] + self.session.headers = {'Authorization': authorization} def get_repos(self, username): user_repos = self._getter( @@ -56,19 +60,14 @@ def _getter(self, url, subkey=None): """ Pagination utility. Obnoxious. """ kwargs = {} - - if 'token' in self.auth: - kwargs['headers'] = { - 'Authorization': 'token ' + self.auth['token'] - } - elif 'basic' in self.auth: + if 'basic' in self.auth: kwargs['auth'] = self.auth['basic'] results = [] link = dict(next=url) while 'next' in link: - response = requests.get(link['next'], **kwargs) + response = self.session.get(link['next'], **kwargs) json_res = self.json_response(response) if subkey is not None: diff --git a/bugwarrior/services/pagure.py b/bugwarrior/services/pagure.py index 1e4c8d499..c04ac78ff 100644 --- a/bugwarrior/services/pagure.py +++ b/bugwarrior/services/pagure.py @@ -102,7 +102,7 @@ class PagureService(IssueService): def __init__(self, *args, **kw): super(PagureService, self).__init__(*args, **kw) - self.auth = {} + self.session = requests.Session() self.tag = self.config_get_default('tag') self.repo = self.config_get_default('repo') @@ -141,7 +141,7 @@ def get_issues(self, repo, keys): key3 = key1[:-1] # Just the singular form of key1 url = self.base_url + "/api/0/" + repo + "/" + key1 - response = requests.get(url) + response = self.session.get(url) if not bool(response): error = response.json() @@ -189,7 +189,7 @@ def filter_repos(self, repo): def issues(self): if self.tag: url = self.base_url + "/api/0/projects?tags=" + self.tag - response = requests.get(url) + response = self.session.get(url) if not bool(response): raise IOError('Failed to talk to %r %r' % (url, response))