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') # 可以解决
python bytes to string的更多相关文章
- [Python]Bytes 和 String转换
#----string to bytes------ # 方法一:直接复制bytes类型 b'<str>' b = b'Hello World' print(type(b)) print( ...
- Python中的string和bytes的转换
总的来说,bytes和string的关系是: \(bytes\xrightarrow{decode}string\) \(bytes\xleftarrow{encode}string\) 常见的几种编 ...
- python unicode和string byte
python unicode 和string那 开发过程中总是会碰到string, unicode, ASCII, 中文字符等编码的问题, 每次碰到都要现搜, 很是浪费时间, 于是这次狠下心, 一定要 ...
- Python bytes decode() 方法
描述 bytes decode() 方法以指定的编码格式解码 bytes 对象,默认编码为 'utf-8'. 对应的编码方法:encode() 方法 . 语法 Python bytes decode( ...
- 【RF库测试】Encode String To Bytes&Decode Bytes To String& should be string&should be unicode string &should not be string
场景1:判断类型 r ${d} set variable \xba\xcb\xbc\xf5\xcd\xa8\xb9\xfd #核减通过 Run Keyword And Continue On Fail ...
- python基础===Character string
本文转自:python之Character string 1.python字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串,l Python不支持单 ...
- Python中字符串String的基本内置函数与过滤字符模块函数的基本用法
Python中字符串String的基本内置函数与用法 首先我们要明白在python中当字符编码为:UTF-8时,中文在字符串中的占位为3个字节,其余字符为一个字节 下面就直接介绍几种python中字符 ...
- 各种转码(bytes、string、base64、numpy array、io、BufferedReader )
bytes 与 string 之间互转 Python3 最重要的新特性大概要算是对文本和二进制数据作了更为清晰的区分.文本总是 Unicode,由str类型表示,二进制数据则由 bytes 类型表示. ...
- python之bytes和string
转自:https://www.cnblogs.com/skiler/p/6687337.html 1.bytes主要是给在计算机看的,string主要是给人看的 2.中间有个桥梁就是编码规则,现在大趋 ...
随机推荐
- LoadRunner ERROR:Could not call flex.messaging.io.amf.ASObject.readObject() : Cannot parse date.
Error: Encoding of AMF message failed. Error is : Exception Occurred while invoking WriteObject meth ...
- cocos2dx 3.1获取系统当前时间
std::string Tools::getcurrTime() { #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATF ...
- 学习PYTHON之路, DAY 6 - PYTHON 基础 6 (模块)
一 安装,导入模块 安装: pip3 install 模块名称 导入: import module from module.xx.xx import xx from module.xx.xx impo ...
- AutoCAD2006启动慢解决方案
一. 1.打开控制面板.2.选择Internet选项.3.在Internet属性对话框里,点高级标签.4.清除“检查发行商的证书吊销”选项.5.单击应用,然后单击OK.6.重新启动,运行应用程序. 二 ...
- uva 10934(dp)
题意:k个水球,现在在一个n层建筑物上,水球可能在某一层层以上扔下去会破掉,现在求一个最少的次数使得用这k个水球能确定出哪一层. 思路:假设有i个小球,还可以实验j次时,第一个小球从x处扔下去,如果破 ...
- Linux系统值得一看的学习方法及路线图
网络是一个很神奇的东西,现代人的生活离不开网络,网络已深入人们的工作,生活,娱乐等方方面面.网络之所以无处不在,是因为它提供了诸多的网络服务,所以网络服务是网络的灵魂. 互联网上的各种网络服务是架构在 ...
- jQuery LigerUI V1.2.2 (包括API和全部源码) 发布
前言 这次版本主要对树进行了加载性能上面的优化,并解决了部分兼容性的问题,添加了几个功能点. 欢迎使用反馈. 相关链接 API: http://api.ligerui.com/ 演示地 ...
- OC基础--构造方法 id类型
new方法实现原理: new做了三件事情 1.开辟存储空间 + alloc 方法 2.初始化所有的属性(成员变量) - init 方法 3.返回对象的地址 [Person new]; == [[Pe ...
- Oracle Merge into 详细介绍
Oracle Merge into 详细介绍 /*Merge into 详细介绍MERGE语句是Oracle9i新增的语法,用来合并UPDATE和INSERT语句.通过MERGE语句,根据一张表或子查 ...
- Bash shell的内建命令:type
type指令是用来观察指令时来自于外部指令还是内建在bash中的指令. type [-tpa] name 选项与参数: :不加任何选项与参数时,type会显示出name是外部指令还是bash内建指 ...