美文网首页
post接口传文件错误UnicodeEncodeError

post接口传文件错误UnicodeEncodeError

作者: pandak | 来源:发表于2018-06-07 17:45 被阅读0次
      File "D:\Python\Python36\lib\http\client.py", line 1239, in request
        self._send_request(method, url, body, headers, encode_chunked)
      File "D:\Python\Python36\lib\http\client.py", line 1284, in _send_request
        body = _encode(body, 'body')
      File "D:\Python\Python36\lib\http\client.py", line 161, in _encode
        (name.title(), data[err.start:err.end], name)) from None
    UnicodeEncodeError: 'latin-1' codec can't encode characters in position 195-202: Body ('这个是什么颜色呢') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.
    

    解决办法:在data上加上encode('utf-8'),即data.encode('utf-8')

    相关文章

      网友评论

          本文标题:post接口传文件错误UnicodeEncodeError

          本文链接:https://www.haomeiwen.com/subject/abtnsftx.html