Short summary:
I'm trying to download a zip file from a flask API. I've tested the download using a webpage served from the same api, download works fine. Using the same return value, I am getting a corrupted file when I try to integrate it to my perspective session.More detail:
ignition perspective code, onClick event on a button:# check inputs, make sure they're there
min_timestamp = self.parent.parent.parent.getChild("time_range_picker").custom.selected_min
max_timestamp = self.parent.parent.parent.getChild("time_range_picker").custom.selected_max
if not min_timestamp:
raise Exception('no minimum time selected')
if not max_timestamp:
raise Exception('no maximum time selected')
# do request
system.perspective.print('performing log request with timestamps {} and {}'.format(min_timestamp, max_timestamp))
response = rest.get_synq_logs(min_timestamp, max_timestamp)
system.perspective.download('log_bundle.zip', response)
the "rest.get_synq_logs" function just cleans up some of the formatting, it returns the raw output of the system.net.httpPost function.
From the outputs the timestamps are good, from the logs in my API the request goes as normal. When the download happens, a zip file of the right size is downloaded, but when I try to open it I get an error:
What I've tried:
- I've tried .encode and .decode on the response,
- I've tried not saving it as a "response" variable and just ending the function with rest.get_synq_logs(min_timestamp, max_timestamp)
- I've tried converting to a string
I can't help but feel like there should be a "response" object I can load the thing into. The byte stream coming back should have headers and a bunch of other stuff so I suspect that's what's corrupting my file but I'm not sure.
Thanks in advance!!