Python BadZipFile(“文件不是zip文件”)
因此,我使用提供的代码从api中提取数据:Python BadZipFile(“文件不是zip文件”),python,api,zip,Python,Api,Zip,因此,我使用提供的代码从api中提取数据: #User Parameters apiToken = apitokens surveyId = j fileFormat = 'json' #Static Parameters requestCheckProgress = 0 baseUrl = 'https://sdfs.asdfs.com/API/v3/responseexports/'
#User Parameters
apiToken = apitokens
surveyId = j
fileFormat = 'json'
#Static Parameters
requestCheckProgress = 0
baseUrl = 'https://sdfs.asdfs.com/API/v3/responseexports/'
headers = {
'content-type': "application/json",
'x-api-token': apiToken,
}
#Creating Data Export
downloadRequestUrl = baseUrl
downloadRequestPayload = '{"format":"' + fileFormat + '","surveyId":"' + surveyId + '"}'
downloadRequestResponse = requests.request("POST", downloadRequestUrl, data=downloadRequestPayload, headers=headers)
progressId = downloadRequestResponse.json()['result']['id']
print (downloadRequestResponse.text)
#Checking on Data Export
while requestCheckProgress < 100:
requestCheckUrl = baseUrl + progressId
requestCheckResponse = requests.request("GET", requestCheckUrl, headers=headers)
requestCheckProgress = requestCheckResponse.json()['result']['percentComplete']
print ("Download is " + str(requestCheckProgress) + " complete")
#Downloading file
requestDownloadUrl = baseUrl + progressId + '/file'
requestDownload = requests.request("GET", requestDownloadUrl, headers=headers, stream=True)
with open('RequestFile.zip', "wb") as f:
for chunk in requestDownload.iter_content(chunk_size=1024):
f.write(chunk)
zipfile.ZipFile('RequestFile.zip').extractall("sdafsadf")
else:
print("error")
下载量大约为1350%。我似乎找不到他们代码中的错误。我正在使用Python3.6,也尝试过使用3.5
zipfile.BadZipFile: File is not a zip file