def download_file(server_name, report_url, session_id, file_name):
headers = {'content-type': 'application/json'}
try:
r = requests.get(report_url, headers=headers, verify=False, stream=True)
# if HTTP Response is not 200 then raise an exception
if r.status_code != 200:
message = "The HTTP response for get call to the server is not 200."
raise TintriApiException(message, r.status_code, report_url, "No Payload", r.text)
with open(file_name, 'w') as file_h:
for block in r.iter_content(4096):
file_h.write(block)
except requests.ConnectionError:
raise TintriRequestsException("API Connection error occurred.")
except requests.HTTPError:
raise TintriRequestsException("HTTP error occurred.")
except requests.Timeout:
raise TintriRequestsException("Request timed out.")
except Exception as e:
raise TintriRequestsException("An unexpected error: " + e.__str__())
评论列表
文章目录