Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新接口响应json序列化逻辑 #177

Merged
merged 4 commits into from
Apr 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions httpfpt/common/send_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,21 @@ def send_request(
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)
res_headers = dict(response.headers)
response_data['headers'] = res_headers
response_data['cookies'] = dict(response.cookies)
res_content_type = res_headers.get('Content-Type')
try:
json_data = response.json()
if res_content_type and 'application/json' in res_content_type:
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['content'] = response.content
response_data['text'] = response.text
response_data['request'] = request_data_parsed

Expand Down
Loading