我正在构建一个需要两个服务来交换泡菜文件或 python 对象的小型应用程序,任何人都会这样做。因为我是 Django 的新手,所以我很难做到这一点。请看代码。发件人:
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
接收者:
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)
上面的代码不起作用。它正在生成空文件或 KeyError 101