Skip to content

Fix http.py: Exception -> exception. #724

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion googleapiclient/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ def _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args,
"""
resp = None
content = None
exception = None
for retry_num in range(num_retries + 1):
if retry_num > 0:
# Sleep before retrying.
sleep_time = rand() * 2 ** retry_num
LOGGER.warning(
'Sleeping %.2f seconds before retry %d of %d for %s: %s %s, after %s',
sleep_time, retry_num, num_retries, req_type, method, uri,
resp.status if resp else Exception)
resp.status if resp else exception)
sleep(sleep_time)

try:
Expand Down
4 changes: 3 additions & 1 deletion samples/coordinate/coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

from oauth2client import client
from googleapiclient import sample_tools
from googleapiclient.discovery import build
from googleapiclient.discovery import http

# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
Expand All @@ -61,7 +63,7 @@ def main(argv):

try:
# List all the jobs for a team
jobs_result = service.jobs().list(teamId=FLAGS.teamId).execute(http=http)
jobs_result = service.jobs().list(teamId=flags.teamId).execute(http=http)

print('List of Jobs:')
pprint.pprint(jobs_result)
Expand Down
8 changes: 6 additions & 2 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,12 @@ class TestMediaUpload(unittest.TestCase):
def test_media_file_upload_closes_fd_in___del__(self):
file_desc = mock.Mock(spec=io.TextIOWrapper)
opener = mock.mock_open(file_desc)
with mock.patch('__builtin__.open', return_value=opener):
upload = MediaFileUpload(datafile('test_close'), mimetype='text/plain')
if PY3:
with mock.patch('builtins.open', return_value=opener):
upload = MediaFileUpload(datafile('test_close'), mimetype='text/plain')
else:
with mock.patch('__builtin__.open', return_value=opener):
upload = MediaFileUpload(datafile('test_close'), mimetype='text/plain')
self.assertIs(upload.stream(), file_desc)
del upload
file_desc.close.assert_called_once_with()
Expand Down