0

I'm trying to send a binary file from a client that runs on ironPython 2.7.4 to a server that runs on cpython 2.7.6 on a linuxbox. I followed this example, however when the server starts writing the file (first call to f.write), I get an Error:

TypeError: must be string or buffer, not int

Here the I think relevant pieces of the code.

server:

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()

client:

f = open(fname, 'rb') 
chunk = f.read(1024)
while (chunk):
    self.conn.send(chunk)
    chunk = f.read(1024)

f.close()

conn is the socket connection - this works, I can transfer pickled dicts successfully.

Any hints?

thanks and regards, Dominic

1 Answer 1

0
f.write(chunk)

should do it (instead of f.write(1024).

As the error message states, f.write expects a string parameter, and 1024 is clearly an int

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, of course, now I feel quite stupid...Thanks for curing my blindness :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.