Passing pickle file or Python object between two Django servers

435 Views Asked by At

I'm building a small application which requires two serves to exchange pickle file or a python object , anyone will do. As i am new to Django, i having hard time doing so. Please look at the code. Sender:

def get(self, request):
    message ="hello"
    pickle.dump(message, open("test.p", "wb"))
    filename = "test.p"
    #content = 'any string generated by django'
    response = HttpResponse(message, mime_type='application/python-pickle')
    response['Content-Disposition'] = 'attachment; filename={0}'.format(filename)
    return response

Receiver:

with open("sample1.p", 'wb') as fd:
    for chunk in response.iter_content():
        fd.write(chunk)

with open("sample1.p", 'rb') as handle:
    var = pickle.load(handle)

the above code is not working. Either it is generating empty files or KeyError 101

0

There are 0 best solutions below