2
z = zipfile.ZipFile("zipfile.zip", "w")
z.write(filename)

It takes string as an argument that is actually path of that file to be add to the zip. But I want to add dynamically generated file.

Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

1

yes, if you have a buffer you want to dump in your zip file, you can use writestr so you avoid creating a temp file:

z.writestr(filename,my_buffer)

my_buffer maybe a str (string) or bytes

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
  • Like How ? generated pdf file is in the form of HttpResponse and also in form of object of pdfkit. – Bhirendra Kumar Sahu Feb 27 '17 at 15:31
  • `response.read()` gives you `json` I suppose, and you can `json.loads()` it to convert to a dict. The question was unclear about that. It's technically answered. You may want to edit it to provide an example / snippet of what the response returns. I don't mind looking further into it. – Jean-François Fabre Feb 27 '17 at 15:34
  • Thanks. But It is showing error while reading response data ` 'HttpResponse' object has no attribute 'read' ` . Still facing on it. – Bhirendra Kumar Sahu Feb 28 '17 at 05:48