Python 3.x: TypeError: a bytes-like object is required, not 'str'
2018-02-04 16:34
976 查看
使用Python 3.6写tcp客户端程序时,出现“TypeError: a bytes-like object is required, not 'str'”错误提示。
解决方法,在数据发送之前,加上“data=data.encode()”。
# send some data
data="GET / HTTP/1.1\r\nHost: cn.bing.com\r\n\r\n"
data=data.encode()#添加此行
client.send(data)
解决方法,在数据发送之前,加上“data=data.encode()”。
# send some data
data="GET / HTTP/1.1\r\nHost: cn.bing.com\r\n\r\n"
data=data.encode()#添加此行
client.send(data)
相关文章推荐
- python 3.5: TypeError: a bytes-like object is required, not 'str' when writing to a file
- Python中3+版本运行2+版本程序出现TypeError: a bytes-like object is required, not 'str'之读取PDF中的图片
- Python 3.x Error:TypeError: a bytes-like object is required, not 'str'
- python3中,socket使用send函数时出现的错误:TypeError: a bytes-like object is required, not 'str'
- python中Base64编码和解码:TypeError: a bytes-like object is required, not 'str'
- Python 3.5 Socket TypeError: a bytes-like object is required, not 'str' 错误提示
- python3.5 模拟UDP客户端发送数据报文,报错:TypeError: a bytes-like object is required, not 'str'
- python socket send 函数 报错:TypeError: a bytes-like object is required, not 'str'
- python write()参数错误,导致报错TypeError: a bytes-like object is required, not 'str'
- Python学习中出现TpyeErrora bytes-like object is required, not 'str'
- TypeError: a bytes-like object is required, not 'str'
- TypeError: a bytes-like object is required, not 'str'
- 【Python】TypeError: a bytes-like object is required, not 'str'解决
- python3 TypeError: a bytes-like object is required, not 'str'
- python 3.5: TypeError: a bytes-like object is required, not 'str'
- 【Python】TypeError: a bytes-like object is required, not 'str'解决
- Python中“a bytes-like object is required, not 'str'”的问题
- 解决python3的pickle.load错误:a bytes-like object is required, not 'str'
- Python 3.5 Socket TypeError: a bytes-like object is required, not 'str' 错误提示
- python3 TypeError: a bytes-like object is required, not 'str'