Skip to content

fix(utils): decode response body in exception for readability #38

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Nagato-Yuzuru
Copy link

Ensure response body is decoded to UTF-8 when raising ResponseException,

Ensure response body is decoded to UTF-8 when raising ResponseException,
@Nagato-Yuzuru
Copy link
Author

Nagato-Yuzuru commented Jul 28, 2025

支付异常抛出的时候尝试拿到response内容,标准库签名如下:

 http.client.HTTPResponse
def read(self, amt: int | None = None) -> bytes

Read and return the response body, or up to the next amt bytes.

报错信息

.venv/lib/python3.13/site-packages/alipay/aop/api/util/WebUtils.py:148

    raise ResponseException('[' + THREAD_LOCAL.uuid + ']invalid http status ' + str(response.status) + \
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           ',detail body:' + response.read())
                           ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
TypeError: can only concatenate str (not "bytes") to str

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant