TypeError: unicode strings are not supported, please encode to bytes: 'hu'
来源:互联网 发布:秦夕妍少女时捏脸数据 编辑:程序博客网 时间:2024/05/22 04:48
1、错误描述
>>> t=serial.Serial("COM3",4800);>>> n=t.write('00000200=0000020');Traceback (most recent call last): File "<pyshell#5>", line 1, in <module> n=t.write('00000200=0000020'); File "D:\Python\Python36\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialwin32.py", line 308, in write data = to_bytes(data) File "D:\Python\Python36\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialutil.py", line 63, in to_bytes raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))TypeError: unicode strings are not supported, please encode to bytes: '00000200=0000020'>>> n=t.write('hu');Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> n=t.write('hu'); File "D:\Python\Python36\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialwin32.py", line 308, in write data = to_bytes(data) File "D:\Python\Python36\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialutil.py", line 63, in to_bytes raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))TypeError: unicode strings are not supported, please encode to bytes: 'hu'>>>
2、错误原因
需要将传输的字符串添加encode()方法,需要对字符串进行编码
3、解决办法
>>> n=t.write('00000200=00000200'.encode());>>> print(t.portstr);COM3>>> print(n);17>>> s=t.read(n);print(s);
0 0
- TypeError: unicode strings are not supported, please encode to bytes: 'hu'
- TypeError: decoding Unicode is not supported
- TypeError: decoding Unicode is not supported
- TypeError: expected bytes, not str
- python3 unicode bytes decode encode之间联系
- jenkins报错strings in switch are not supported in -source 1.5
- This server version is not supported. Only servers up to Microsoft SQL Server 2005 are supported.
- python 3.5: TypeError: a bytes-like object is required, not 'str' when writing to a file
- TypeError: must be str, not bytes
- TypeError: 'bytes' object is not callable解决办法
- TypeError: must be str, not bytes
- Flex中TypeError: Error #1089: Assignment to lists with more than one item is not supported.
- python3 TypeError:Unicode-objects must be encode before hashing
- Deprecated Thread methods are not supported.
- PNG images are not supported问题解决
- c# Nested transactions are not supported
- git binary diffs are not supported 问题
- 保存网页TypeError: must be str, not bytes
- EFT电快速脉冲群测试
- 多线程及I/O面试题
- 深入理解Java:类加载机制及反射
- JNDI+Tomcat配置数据源的两种方式
- 何洋开讲丨企业引入新技术,遇到阻力怎么办?
- TypeError: unicode strings are not supported, please encode to bytes: 'hu'
- docker常用命令
- 微软2017预科生编程
- Oracle多数据库创建
- 剑指Offer——(22)从上往下打印二叉树&&层次遍历
- RS-485通讯协议
- Android-服务Service(3)-IntentService
- Friends and Subsequences
- 何洋开讲丨深度分析!《人民的名义》样片泄露内幕