Skip to content

Commit

Permalink
更新接口响应json序列化逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-clan committed Apr 12, 2024
1 parent 9a2add6 commit c5c97ef
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions httpfpt/common/send_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,21 @@ def send_request(
raise SendRequestError('请求发起失败,请使用合法的请求引擎:requests / httpx')

# 记录响应数据
res_headers = dict(response.headers)
response_data['url'] = str(response.url)
response_data['status_code'] = int(response.status_code)
response_data['elapsed'] = response.elapsed.microseconds / 1000.0
response_data['headers'] = dict(response.headers)
response_data['headers'] = res_headers
response_data['cookies'] = dict(response.cookies)
try:
json_data = response.json()
if res_headers.get('content-type') == 'application/json':
json_data = response.json()
else:
json_data = {}
except JSONDecodeError:
log.warning('响应数据解析失败,响应数据不是有效的 json 格式')
json_data = {}
err_msg = '响应数据解析失败,响应数据不是有效的 json 格式'
log.warning(err_msg)
raise SendRequestError(err_msg)
response_data['json'] = json_data
response_data['content'] = response.content.decode('utf-8')
response_data['text'] = response.text
Expand Down

0 comments on commit c5c97ef

Please sign in to comment.