From f177ffe680624e252348df980ec5db97ab0728ba Mon Sep 17 00:00:00 2001 From: debugtalk Date: Wed, 21 Mar 2018 22:34:49 +0800 Subject: [PATCH] fix #120: UnicodeEncodeError occured when response text contains Chinese in Python 2 --- httprunner/__about__.py | 2 +- httprunner/client.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/httprunner/__about__.py b/httprunner/__about__.py index e7621d38..09868d17 100644 --- a/httprunner/__about__.py +++ b/httprunner/__about__.py @@ -1,7 +1,7 @@ __title__ = 'HttpRunner' __description__ = 'One-stop solution for HTTP(S) testing.' __url__ = 'https://github.com/HttpRunner/HttpRunner' -__version__ = '1.2.2-beta' +__version__ = '1.2.3-beta' __author__ = 'debugtalk' __author_email__ = 'mail@debugtalk.com' __license__ = 'MIT' diff --git a/httprunner/client.py b/httprunner/client.py index 5f3efa38..3d091af2 100644 --- a/httprunner/client.py +++ b/httprunner/client.py @@ -5,6 +5,7 @@ import requests import urllib3 from httprunner import logger from httprunner.exception import ParamsError +from httprunner.utils import PYTHON_VERSION from requests import Request, Response from requests.exceptions import (InvalidSchema, InvalidURL, MissingSchema, RequestException) @@ -113,7 +114,10 @@ class HttpSession(requests.Session): self.meta_data["request_body"] = response.request.body self.meta_data["status_code"] = response.status_code self.meta_data["response_headers"] = response.headers + self.meta_data["response_body"] = response.text + if PYTHON_VERSION == 2 and isinstance(self.meta_data["response_body"], unicode): + self.meta_data["response_body"] = self.meta_data["response_body"].encode("utf-8") logger.log_debug("response status_code: {}".format(self.meta_data["status_code"])) logger.log_debug("response headers: {}".format(self.meta_data["response_headers"]))