Skip to content

返回值中文编码错误 #8

@fliaping

Description

@fliaping

requests文档中有这样一句话

If Response.encoding is None, encoding will be guessed using chardet.

服务器返回的header中没有编码信息( Content-Encoding),导致api函数最后拿到的json是按照 'chardet'编码,导致乱码,解决办法,手动设置编码

r = requests.post(url, headers=headers, data=json.dumps(data))
r.encoding = 'utf8'
r.json()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions