zoukankan      html  css  js  c++  java
  • python bytes to string

    python bytes 转化成 string 会遇到如下错误:

    codec can't decode byte 0xff in position 5: illegal multibyte sequence

    其实还是编码格式的问题,通过使用: ok_cookies = ok_str.decode('iso-8859-1')

    ok_str = b'\x00\x01\x00\x00\x00\xff\xff\xff\xff\x01\x00\x00\x00\x00\x00\x00\x00\x06\x01\x00\x00\x00\x83\x02JSESSIONID=T2yrYjqcymFWppsLlJRlLkKv12MFvN2XTn90LJP4d8C22bp989pb!1246418420;BIGipServerpool_xwqy=FCvoaVAFKNbKjaDKHq0URsieemJ3jdG54/DLz9FGInF+UEiDGYTJHurg+SIiST4VX9D2VdgYcwvVZ9g=;ipcrs=L7Ng5mBsLk+NqWHttzF8QSOrXK1n1gnYWmBMzGZ2Nsg0/pvY+VVMmy25y6wW1B7yR2NMBOEeTxcB\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    
    ok_cookies = ok_str.decode()  # 'utf-8' codec can't decode byte 0xff in position 5: invalid start byte
    
    ok_cookies = ok_str.decode('gbk')  # 'gbk' codec can't decode byte 0xff in position 5: illegal multibyte sequence
    
    ok_cookies = ok_str.decode('iso-8859-1') # 可以解决
    

      

  • 相关阅读:
    [angularjs] angularjs系列笔记(五)Service
    [android] 隐式意图的配置
    [android] 隐式意图激活另外一个activity
    [angularjs] angularjs系列笔记(四)过滤器
    [android] 显示意图激活另外一个activity
    [android] smartimageview&常见的开源代码
    [angularjs] angularjs系列笔记(四)控制器
    [android] 上传文件到服务器
    [android] 异步http框架与实现原理
    [android] 采用httpclient提交数据到服务器
  • 原文地址:https://www.cnblogs.com/leohao/p/6229912.html
Copyright © 2011-2022 走看看