【发布时间】:2017-10-06 01:13:06
【问题描述】:
我正在编写一个程序来通过套接字将目录发送到客户端。程序的一部分处理使用特定代码创建一个数组(例如:代码 1 表示客户端应该期望文件名,2 表示客户端应该期望文件内容),另一部分处理解码这个数组。但是在使用 .decode() 方法解码时,我得到了
AttributeError: 'builtin_function_or_method' object has no attribute 'decode'
我是套接字编程的新手,但已成功解码通过套接字发送的字符串我做错了什么?
服务器代码:
cab=['1'.encode,c.encode()] #since file is not created, file name 'c' is sent
client.send(pickle.dumps(cab)) #transmits the cab
客户端代码:
cab=pickle.loads(client.recv(r_size))
if(cab):
d=cab[0]
print(d.decode())
return 0
else:
print("error")
【问题讨论】: