Skip to content

Commit

Permalink
修复json数据对象编码 (#75)
Browse files Browse the repository at this point in the history
* 修复json数据对象编码

* 修复格式化错误
  • Loading branch information
wu-clan authored Dec 22, 2023
1 parent 19f5700 commit b624a82
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions httpfpt/common/send_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import time

from json import JSONDecodeError
from json import dumps as json_dumps
from typing import Literal

import allure
Expand Down Expand Up @@ -224,7 +223,7 @@ def send_request(
except JSONDecodeError:
log.warning('响应数据解析失败,响应数据不是有效的 json 格式')
json_data = {}
response_data['json'] = json_dumps(json_data).encode('utf-8')
response_data['json'] = json_data
response_data['content'] = response.content.decode('utf-8')
response_data['text'] = response.text

Expand Down
2 changes: 1 addition & 1 deletion httpfpt/utils/allure_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def allure_step(step: str, var: Union[str, dict]) -> None:
"""
with allure.step(step):
allure.attach(
body=json_dumps(var, ensure_ascii=False, indent=2).encode('utf-8') if isinstance(var, dict) else var,
body=json_dumps(var, ensure_ascii=False, indent=2) if isinstance(var, dict) else var,
name='JSON Serialize',
attachment_type=AttachmentType.JSON,
)
Expand Down
4 changes: 2 additions & 2 deletions httpfpt/utils/request/request_data_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,15 @@ def body(self) -> Union[dict, bytes, str, None]:
elif body_type == BodyType.GraphQL:
if not isinstance(body, dict):
raise RequestDataParseError('参数 test_steps:request:body 不是有效的 dict 类型')
body = json_dumps(body, ensure_ascii=False).encode('utf-8')
body = json_dumps(body, ensure_ascii=False)
elif body_type == BodyType.TEXT: # noqa: SIM114
body = body
elif body_type == BodyType.JavaScript:
body = body
elif body_type == BodyType.JSON:
if not isinstance(body, dict):
raise RequestDataParseError('参数 test_steps:request:body 不是有效的 dict 类型')
body = json_dumps(body, ensure_ascii=False).encode('utf-8')
body = json_dumps(body, ensure_ascii=False)
elif body_type == BodyType.HTML: # noqa: SIM114
body = body
elif body_type == BodyType.XML:
Expand Down

0 comments on commit b624a82

Please sign in to comment.