python3.5 模拟UDP客户端发送数据报文,报错:TypeError: a bytes-like object is required, not 'str'
2017-07-16 16:15
916 查看
#!/usr/bin/env python # -*- coding:utf-8 -*- import socket target_host = "127.0.0.1" target_port = 80 #建立一个socket对象 client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #发送一些数据 response = client.sendto(("AAABBBCCC"),(target_host,target_port)) print(response) #接收一些数据 data, addr = client.recvfrom(4096) print(data)
报错: response = client.sendto(("AAABBBCCC"),(target_host,target_port))
TypeError: a bytes-like object is required, not 'str'
解决方法:
response = client.sendto(("AAABBBCCC").encode(),(target_host.encode(),target_port))
相关文章推荐
- Python 3.5 Socket TypeError: a bytes-like object is required, not 'str' 错误提示
- python 3.5: TypeError: a bytes-like object is required, not 'str' when writing to a file
- Python 3.x: TypeError: a bytes-like object is required, not 'str'
- Python中3+版本运行2+版本程序出现TypeError: a bytes-like object is required, not 'str'之读取PDF中的图片
- python中Base64编码和解码: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'
- python3中,socket使用send函数时出现的错误:TypeError: a bytes-like object is required, not 'str'
- Python 3.x Error:TypeError: a bytes-like object is required, not 'str'
- TypeError: a bytes-like object is required, not 'str'
- python 3.5: TypeError: a bytes-like object is required, not 'str'
- Python 3.5 Socket TypeError: a bytes-like object is required, not 'str' 错误提示
- TypeError: a bytes-like object is required, not 'str'
- Python学习中出现TpyeErrora bytes-like object is required, not 'str'
- python问题:TypeError: a bytes-like object is required, not 'str'
- 解决python3的pickle.load错误:a bytes-like object is required, not 'str'
- python3 TypeError: a bytes-like object is required, not 'str'
- linux下运行python3出现TypeError: a bytes-like object is required, not 'str'
- Error:a bytes-like object is required not str
- 【Python】TypeError: a bytes-like object is required, not 'str'解决