def uploadFile(connection, url, fileName, uploadPath, overwrite=True): headers = {'Content-Type': 'multipart/form-data'} params = {"overwrite": overwrite, "uploadPath": uploadPath} log('Uploading to %s...' % uploadPath) try: with open(fileName, 'rb') as f: resp = requests.post(url, data=f, params=params, headers=headers, verify=False) if resp.ok is not True: raise Exception('POST operation failed with %s' %resp.text) except requests.exceptions.ConnectionError as e: raise Exception( 'Upload file failed. Received connection error. One common cause for this error is the size of the file to be uploaded.' ' The web server sets a limit of 1GB for the uploaded file size. Received the following error: %s' % str(e) ) except IOError as e: raise Exception('Upload file failed. Received IO error: %s' % str(e)) except Exception as e: raise Exception('Upload file failed. Received the following error:\n %s' % str(e)) else: log('Upload file finished.') log('Response status code %s' % resp.status_code) log('Response text %s' % resp.text)