TypeError: can only concatenate str (not “bytes“) to str
执行python脚本时提示“TypeError: can only concatenate str (not "bytes") to str”错误,如图示所示:
原脚本
vk = self.sk.get_verifying_key()
vk_hex = binascii.hexlify(vk.to_string())
vk_x_separated = ""
vk_x_str = vk_hex[0:64]
for i in range(0, len(vk_x_str), 2):
vk_x_separated = "0x" + vk_x_str[i:i+2] + ", " + vk_x_separated
原因是vk_x_str[i:i+2]是byte类型,链接需要str类型,需将vk_x_str[i:i+2]转换为str类型。
更改后的脚本
vk = self.sk.get_verifying_key()
vk_hex = binascii.hexlify(vk.to_string())
vk_x_separated = ""
vk_x_str = vk_hex[0:64]
for i in range(0, len(vk_x_str), 2):
vk_x_separated = "0x" + str(vk_x_str[i:i+2]) + ", " + vk_x_separated
运行新脚本不再提示错误
TypeError: can only concatenate str (not “bytes“) to str相关推荐
- python 解决bytes和str之间 出现 TypeError的问题
解决TypeError: can only concatenate str (not "bytes") to str 错误提示: pic_content = pic_content ...
- Python高能小技巧:了解bytes与str的区别
导读:Python有两种类型可以表示字符序列:一种是bytes,另一种是str. 作者:布雷特·斯拉特金(Brett Slatkin) 来源:大数据DT(ID:hzdashuju) bytes实例包含 ...
- Python 了解 bytes 与 str 的区别
Python 有两种类型可以表示字符序列 bytes:实例包含的是原始数据,即 8 位的无符号值(通常按照 ASCII 编码标准来显示) str:实例包含的是 Unicode 码点(code poin ...
- python3字符编码str_聊聊Python 3 的字符串:str 和 bytes 的区别
Python2的字符串有两种:str 和 unicode,Python3的字符串也有两种:str 和 bytes.Python2 的 str 相当于 Python3 的bytes,而unicode相当 ...
- python里str什么意思_Python 3 字符串中的 STR 和 Bytes 究竟有什么区别?
原标题:Python 3 字符串中的 STR 和 Bytes 究竟有什么区别? Python2的字符串有两种:str和Unicode,Python3的字符串也有两种:str和Bytes.Python2 ...
- python str与bytes之间的转换
python str与bytes之间的转换 # bytes object b = b"example"# str object s = "example" # ...
- 成功解决TypeError: sequence item 0: expected str instance, bytes found
成功解决TypeError: sequence item 0: expected str instance, bytes found 目录 解决问题 解决思路 解决方法 解决问题 TypeError: ...
- python提示错误TypeError: write() argument must be str, not bytes
还是在学习<Machine Learning in Action>中决策树一章中,在学习决策树存储过程中先是提示错误TypeError: write() argument must be ...
- python创建虚拟环境报错typeerror_解决Python中报错TypeError: must be str, not bytes问题
如下所示: #!/usr/bin/python import pickle shoplist=['apple','mango','carrot'] f = open('c:\poem.txt','w' ...
最新文章
- 【linux】shell中整数运算的加、减、乘、除
- 官方翻译不当导致的PowerShell运行失败一例
- php抓取新浪微博数据抓取,php利用curl抓取新浪微博内容示例
- opencl filtering整理
- GOS系列之下载附件
- Swift 新特性 - 访问控制(Access Control)
- c语言课后答案第八章,C++第一至第八章课后习题答案
- Android 环境配置
- android word转html标签,如何将Word转换为网页html格式的方法(附代码清理方法)
- C#中调用halcon引擎来执行hdev程序
- 修改现有用户帐户的 Microsoft Lync Server 2010 属性
- fork的写时复制1
- 计算机组成原理(白中英) 第八章 课后题答案
- Typora下载与安装
- 投影仪融合、拼接处理系统
- 北京大学计算机考研专业课考什么,北大计算机怎样考
- 阿里、京东、百度“激战”互联网医疗
- 架构师学习笔记(四)架构师线路之系统架构师企业架构师
- 我国网民规模近10亿:4成初中学历 近3成月收入超5000元
- 【MSSQL】SQL SERVER导入中文乱码问题解决