Skip to content

Commit 5f00cad

Browse files
ittusnathanielmanistaatgoogle
authored andcommitted
Fix unprintable message with BatchError repr (#165)
1 parent df61397 commit 5f00cad

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

googleapiclient/errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ def __init__(self, reason, resp=None, content=None):
126126
self.reason = reason
127127

128128
def __repr__(self):
129+
if getattr(self.resp, 'status', None) is None:
130+
return '<BatchError "%s">' % (self.reason)
131+
else:
129132
return '<BatchError %s "%s">' % (self.resp.status, self.reason)
130133

131134
__str__ = __repr__

tests/test_http.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,9 @@ def test_add_fail_for_resumable(self):
10531053
upload = MediaFileUpload(
10541054
datafile('small.png'), chunksize=500, resumable=True)
10551055
self.request1.resumable = upload
1056-
self.assertRaises(BatchError, batch.add, self.request1, request_id='1')
1056+
with self.assertRaises(BatchError) as batch_error:
1057+
batch.add(self.request1, request_id='1')
1058+
str(batch_error.exception)
10571059

10581060
def test_execute_empty_batch_no_http(self):
10591061
batch = BatchHttpRequest()

0 commit comments

Comments
 (0)