【发布时间】:2015-11-30 20:48:38
【问题描述】:
我正在尝试将二进制文件从运行在 ironPython 2.7.4 上的客户端发送到运行在 linuxbox 上的 cpython 2.7.6 上的服务器。我遵循this 示例,但是当服务器开始写入文件时(第一次调用f.write),我得到一个错误:
TypeError: must be string or buffer, not int
这里是我认为相关的代码。
服务器:
def recvall(self, count):
msgparts = []
while count > 0:
newbuf = self.conn.recv(count)
if not newbuf: return None
msgparts.append(newbuf)
count -= len(newbuf)
#print "%i bytes left" % count
return "".join(msgparts)
#receive file, write out
f = open(fname, 'wb')
chunk = self.recvall(1024)
while (chunk):
f.write(1024) #<-- error happens here.
chunk = self.recvall(1024)
f.close()
客户:
f = open(fname, 'rb')
chunk = f.read(1024)
while (chunk):
self.conn.send(chunk)
chunk = f.read(1024)
f.close()
conn 是套接字连接 - 这行得通,我可以成功传输腌制的字典。
有什么提示吗?
感谢和问候, 多米尼克
【问题讨论】:
标签: python sockets ironpython typeerror file-transfer