Sam Bull <[email protected]> added the comment:
I think there's a much simpler solution to this ticket than the retry logic
that's currently in place.
The code originally avoided the infinite recursion by checking to see if the
previous request had already submitted the auth credentials that would be used
in the retry. If it had, it would return None. If it hadn't, it would add the
auth credentials to the request header and the request again:
if req.headers.get(self.auth_header, None) == auth:
return None
req.add_header(self.auth_header, auth)
Then, to fix #3819, it was changed. Instead of calling add_header, it called
add_unredirected_header:
if req.headers.get(self.auth_header, None) == auth:
return None
req.add_unredirected_header(self.auth_header, auth)
This caused the loop because the auth creds were going into unredirected_hdrs
instead of the headers dict.
But I think the original logic is sound. The code just wasn't checking in all
the headers. Luckily there's a get_header method that checks both for you. This
one-line change should fix the issue:
if req.get_header(self.auth_header, None) == auth:
return None
req.add_unredirected_header(self.auth_header, auth)
I think this fix is cleaner and makes more sense, but I'm worried I might be
missing something. I don't fully understand the distinction between headers and
unredirected headers. Maybe there's a reason why the code isn't checking in
unredirected headers for the auth header.
I'm attaching a patch. I'm new to contributing to python so I apologize if the
format is wrong.
----------
nosy: +sambull
versions: +Python 2.7
Added file: http://bugs.python.org/file20471/simpler_fix.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue8797>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com