From ce7eebfc1f523680c41b03eb2b4d5e7bebe29013 Mon Sep 17 00:00:00 2001 From: Vanessasaurus <814322+vsoch@users.noreply.github.com> Date: Tue, 12 Oct 2021 09:29:22 -0600 Subject: allowing spack monitor to handle redirect (#26666) when deployed on kubernetes, the server sends back permanent redirect responses. This is elegantly handled by the requests library, but not urllib that we have to use here, so I have to manually handle it by parsing the exception to get the Location header, and then retrying the request there. Signed-off-by: vsoch --- lib/spack/spack/monitor.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib') diff --git a/lib/spack/spack/monitor.py b/lib/spack/spack/monitor.py index ac45fadb97..d3a66c6d9b 100644 --- a/lib/spack/spack/monitor.py +++ b/lib/spack/spack/monitor.py @@ -278,6 +278,22 @@ class SpackMonitorClient: ) return self.issue_request(request, False) + # Handle permanent re-directs! + elif hasattr(e, "code") and e.code == 308: + location = e.headers.get('Location') + + request_data = None + if request.data: + request_data = sjson.load(request.data.decode('utf-8'))[0] + + if location: + request = self.prepare_request( + location, + request_data, + self.headers + ) + return self.issue_request(request, True) + # Otherwise, relay the message and exit on error msg = "" if hasattr(e, 'reason'): -- cgit v1.2.3-70-g09d2