prepare_kwargs: reference kwargs do not need to return

This commit is contained in:
httprunner
2017-08-29 15:17:52 +08:00
parent 953a1d54ca
commit d3a068cb6d
2 changed files with 5 additions and 7 deletions

View File

@@ -12,15 +12,13 @@ from requests.exceptions import (InvalidSchema, InvalidURL, MissingSchema,
absolute_http_url_regexp = re.compile(r"^https?://", re.I)
def process_kwargs(method, **kwargs):
def prepare_kwargs(method, kwargs):
if method == "POST":
# if request content-type is application/json, request data should be dumped
content_type = kwargs.get("headers", {}).get("content-type", "")
if content_type.startswith("application/json") and "data" in kwargs:
kwargs["data"] = json.dumps(kwargs["data"])
return kwargs
class ApiResponse(Response):
@@ -152,7 +150,7 @@ class HttpSession(requests.Session):
Safe mode has been removed from requests 1.x.
"""
try:
kwargs = process_kwargs(method, **kwargs)
prepare_kwargs(method, kwargs)
return requests.Session.request(self, method, url, **kwargs)
except (MissingSchema, InvalidSchema, InvalidURL):
raise