37,719
社区成员
发帖
与我相关
我的任务
分享
def send_back_no_header(newSocket,response,isNeedHeader=True):
try:
print('send_back_no_header response is:',response)
jresp = json.dumps(response)
final_resp = bytes(jresp,encoding="utf-8")
print("final_resp is:",final_resp)
if isNeedHeader:
length_resp = len(final_resp)
print("length_resp is:",length_resp)
resp_len = struct.pack('i',length_resp)
print("resp_len is:",resp_len)
newSocket.send(resp_len)
newSocket.send(final_resp)
print("end send ")
except Exception as e:
print('send_back_no_header e is:',e)
descriptor 'send' requires a '_socket.socket' object but received a 'bytes'