Skip to content

Commit 68fb6f6

Browse files
committed
Warn rather than raise on opportunistic auth failure.
When opportunistic_auth is enabled but an Authorization header could not be generated opportunistically, log a warning rather than raising an exception. (If the request results in a 401 and we fail to generate an Authorization header in that (no- longer-opportunistic) case, an exception is still raised.)
1 parent 492a4ab commit 68fb6f6

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

HISTORY.rst

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
History
22
=======
33

4+
Unreleased
5+
----------
6+
7+
- When opportunistic_auth is enabled but an Authorization header
8+
could not be generated opportunistically, log a warning rather
9+
than raising an exception. (If the request results in a 401
10+
and we fail to generate an Authorization header in that (no-
11+
longer-opportunistic) case, an exception is still raised.)
12+
413
1.2.3: 2021-02-08
514
-----------------
615

requests_gssapi/gssapi_.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,20 @@ def __call__(self, request):
306306
# by the 401 handler
307307
host = urlparse(request.url).hostname
308308

309-
auth_header = self.generate_request_header(None, host,
310-
is_preemptive=True)
311-
312-
log.debug(
313-
"HTTPSPNEGOAuth: Preemptive Authorization header: {0}"
314-
.format(auth_header))
315-
316-
request.headers['Authorization'] = auth_header
309+
try:
310+
auth_header = self.generate_request_header(None, host,
311+
is_preemptive=True)
312+
except SPNEGOExchangeError as exc:
313+
log.warning(
314+
"HTTPSPNEGOAuth: Opportunistic auth failed with %s ->"
315+
" sending request without adding Authorization header",
316+
exc,
317+
)
318+
else:
319+
log.debug(
320+
"HTTPSPNEGOAuth: Preemptive Authorization header: {0}"
321+
.format(auth_header))
322+
request.headers['Authorization'] = auth_header
317323

318324
request.register_hook('response', self.handle_response)
319325
try:

0 commit comments

Comments
 (0)