[kudu REST API upload zip] Number of entries expected in End Of Central Directory does not correspond to number of entries in Central Directory
See original GitHub issueHi team,
I’m trying to upload a zip file to my azure function app using python.
I have verified the REST api: (PUT /api/zip/{path}/) can work in the postman.
But when I start to write the python script, I got the 500 error message:
{
"Message": "An error has occurred.",
"ExceptionMessage": "Number of entries expected in End Of Central Directory does not correspond to number of entries in Central Directory.",
"ExceptionType": "System.IO.InvalidDataException",
"StackTrace": " at System.IO.Compression.ZipArchive.ReadCentralDirectory()\r\n at System.IO.Compression.ZipArchive.get_Entries()\r\n at Kudu.Core.Infrastructure.ZipArchiveExtensions.Extract(ZipArchive archive, String directoryName)\r\n at Kudu.Services.Zip.ZipController.<CreateDirectoryPutResponse>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
My python code is written like this:
files = {"file": open(ZIP_FILE_NAME, 'rb')}
response = requests.put(url=url, auth=(usr, pwd), files=files)
if response.status_code not in [200, 201]:
return False
else:
return True
and some refrences about the requests lib is here.
My request header:
{
'Content-Length': '1254',
'Accept-Encoding': 'gzip, deflate',
'Accept': '*/*',
'User-Agent': 'python-requests/2.13.0',
'Connection': 'keep-alive',
'Content-Type': 'multipart/form-data; boundary=9963ab3e05c0477eb70f72a0a8813238',
'Authorization': 'Basic <hidden_base64_string>'
}
To verified if my upload script is wrong. I also wrote a simple server code to receive the upload file and it can receive the zip file. And the received zip file can be unzipped successfully.
Any suggestions about what’s wrong here?
Thanks
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:11 (4 by maintainers)
Top Results From Across the Web
End of Central Directory record could not be found
The problem is ZipFile can't find the line of code that signals the end of the archive, so either: It is not a...
Read more >creating payload with a zip file as for requests to Azur ...
I try to deploy the Azure function by using Rest API and zip-archive of solution. It works properly in Postman. I've found advice...
Read more >[kudu REST API upload zip] Number of entries expected in ...
[kudu REST API upload zip] Number of entries expected in End Of Central Directory does not correspond to number of entries in Central...
Read more >Kudu: /api/zipdeploy fails with "End of Central Directory ...
It did work previously, but now I keep getting the error above. The log/error given by the failure. This is the logs I...
Read more >How to fix "Central Directory Corrupt" in Azure App Service ...
I have an Angular app that I've deployed to azure using the VS Code extension "Azure App Service". It has worked previously, but...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
try this instead
You can check this https://github.com/c9/vfs-http-adapter for the specs vfs and zip controllers are implementing (though they are not a complete implementation)
Ok, so it sounds like the root of the issue was that the request was incorrect on the client, trying to pass the file as form data instead of binary.