Currently I am making a call to an API an that sends back a zip file. When using requests
res = requests.post('http://url/to/api', files={'file_pro': *my_file*})
I am able to get a successful response with the returned zip as a string. When I examine the contents of my res.contents I get :
PK\x03\x04\x14\x00\x00\x00\x08\x00\x0c\x83HH\xba\xd2\xf1\t\xa1\x00\x00\x00\x04\x01\x00\x00....05\x06\x00\x00\x00\x00\x08\x00\x08\x00\x1e\x02\x00\x00$\x04\x00\x00\x00\x00
It looks like its returning the zip file as a string. I looked at this question here to attempt to transform this string into the original zip file. Specifically I wrote:
my_file = UploadedFile(file=File(zipfile.ZipFile(StringIO.StringIO(res.content)),'r'))
my_file.save()
Upon trying to save I get the following error:
KeyError: 'There is no item named 65536 in the archive'
My ultimate goal is to bind this zip file to an UploadedFile
class UploadedFile(BaseModel):
file = models.FileField(upload_to='/path', max_length=255)
If I use a html form to reach this API my browser automatically downloads the zip after the request is successful. Any idea how to fix this?