Add logging and debug report for python client.

This commit is contained in:
geekerzp
2015-07-09 10:11:25 +08:00
parent d97b0984cb
commit 8a3c64aa41
4 changed files with 78 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ import io
import json
import ssl
import certifi
import logging
# python 2 and python 3 compatibility library
from six import iteritems
@@ -27,6 +28,9 @@ except ImportError:
from urllib import urlencode
logger = logging.getLogger(__name__)
class RESTResponse(io.IOBase):
def __init__(self, resp):
@@ -125,6 +129,18 @@ class RESTClientObject(object):
headers=headers)
r = RESTResponse(r)
<<<<<<< HEAD
=======
# log response body
logger.debug("response body: %s" % r.data)
if r.status not in range(200, 206):
raise ApiException(r)
return self.process_response(r)
def process_response(self, response):
>>>>>>> Add logging and debug report for python client.
# In the python 3, the response.data is bytes.
# we need to decode it to string.
if sys.version_info > (3,):