20
20
class Response (object ):
21
21
"""Holds the response from an API call."""
22
22
23
- def __init__ (self , response , method ):
23
+ def __init__ (self , response ):
24
24
"""
25
25
:param response: The return value from a open call
26
26
on a urllib.build_opener()
@@ -29,14 +29,6 @@ def __init__(self, response, method):
29
29
self ._status_code = response .getcode ()
30
30
self ._body = response .read ()
31
31
self ._headers = response .info ()
32
- self ._method = method
33
-
34
- @property
35
- def method (self ):
36
- """
37
- :return: string, method of API call
38
- """
39
- return self ._method
40
32
41
33
@property
42
34
def status_code (self ):
@@ -181,15 +173,14 @@ def _make_request(self, opener, request, timeout=None):
181
173
"""
182
174
timeout = timeout or self .timeout
183
175
try :
184
- return (opener .open (request , timeout = timeout ),
185
- request .get_method ())
176
+ return opener .open (request , timeout = timeout )
186
177
except HTTPError as err :
187
- exc = handle_error (err )
188
- exc .__cause__ = None
189
- _logger .info ('{method} Response: {status} {body}' .format (
178
+ _logger .debug ('{method} Response: {status} {body}' .format (
190
179
method = request .get_method (),
191
180
status = exc .status_code ,
192
181
body = exc .body ))
182
+ exc = handle_error (err )
183
+ exc .__cause__ = None
193
184
raise exc
194
185
195
186
def _ (self , name ):
@@ -272,20 +263,19 @@ def http_request(
272
263
data = data ,
273
264
)
274
265
request .get_method = lambda : method
275
- timeout = kwargs .pop ('timeout' , None )
276
- _logger .info ('{method} Request: {url}' .format (
266
+ _logger .debug ('{method} Request: {url}' .format (
277
267
method = request .get_method (),
278
268
url = request .get_full_url ()))
279
269
if request .data :
280
- _logger .info ('PAYLOAD: {data}' .format (
270
+ _logger .debug ('PAYLOAD: {data}' .format (
281
271
data = request .data ))
282
- _logger .info ('HEADERS: {headers}' .format (
272
+ _logger .debug ('HEADERS: {headers}' .format (
283
273
headers = request .headers ))
284
274
response = Response (
285
- * self ._make_request (opener , request , timeout = timeout )
275
+ self ._make_request (opener , request , timeout = timeout )
286
276
)
287
- _logger .info ('{method} Response: {status} {body}' .format (
288
- method = response . method ,
277
+ _logger .debug ('{method} Response: {status} {body}' .format (
278
+ method = method ,
289
279
status = response .status_code ,
290
280
body = response .body ))
291
281
return response
0 commit comments