kennethreitz/requests — Issue #298: File upload not working with HTTP digest authentication
Author: ibrechin
Created: 2011-12-05 16:25:41+00:00
State: open

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.