This is due to a couple of issues involved with the fact that it is necessary to create two requests and the file already having been read and a boundary set in the content-type header by the first request, resulting in the second (authenticated) request lacking file data and having an incorrect boundary even if you reset the file input stream.
However, more than that it seems like a waste of bytes to send POST data up with the initial request which you know will come back as 401. As a quick fix in my own project I have added an if statement around lines 360-388 in models.py with the conditional
if (not isinstance(self.auth, HTTPDigestAuth)) or 'Authorization' in self.headers:
but I expect there is a more elegant way. If there already exists a way to do an empty first request when using HTTP Digest then I was unable to find it.
Thanks for the report. I'm really unhappy with the post-hook thing that's being used in the Digest Auth handler. It feels really messy.
I'd love to take a more elegant approach, but nothing seems immediately obvious.
Encode Multipart Post data at Request creation
This fixes #298 (File upload not working with
HTTP digest authentication)