From 935d6df839a9b564714037ba32b46b06a8f741b1 Mon Sep 17 00:00:00 2001 From: faucct Date: Tue, 30 Mar 2021 08:13:15 +0300 Subject: [PATCH 1/2] Correct 'Content-Type' headers --- notebook/gateway/managers.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/notebook/gateway/managers.py b/notebook/gateway/managers.py index 199f3f4c89..7674b9ee46 100644 --- a/notebook/gateway/managers.py +++ b/notebook/gateway/managers.py @@ -401,7 +401,9 @@ async def start_kernel(self, kernel_id=None, path=None, **kwargs): json_body = json_encode({'name': kernel_name, 'env': kernel_env}) - response = await gateway_request(kernel_url, method='POST', body=json_body) + response = await gateway_request( + kernel_url, method='POST', headers={'Content-Type': 'application/json'}, body=json_body + ) kernel = json_decode(response.body) kernel_id = kernel['id'] self.log.info("Kernel started: %s" % kernel_id) @@ -489,7 +491,9 @@ async def restart_kernel(self, kernel_id, now=False, **kwargs): """ kernel_url = self._get_kernel_endpoint_url(kernel_id) + '/restart' self.log.debug("Request restart kernel at: %s", kernel_url) - response = await gateway_request(kernel_url, method='POST', body=json_encode({})) + response = await gateway_request( + kernel_url, method='POST', headers={'Content-Type': 'application/json'}, body=json_encode({}) + ) self.log.debug("Restart kernel response: %d %s", response.code, response.reason) async def interrupt_kernel(self, kernel_id, **kwargs): @@ -502,7 +506,9 @@ async def interrupt_kernel(self, kernel_id, **kwargs): """ kernel_url = self._get_kernel_endpoint_url(kernel_id) + '/interrupt' self.log.debug("Request interrupt kernel at: %s", kernel_url) - response = await gateway_request(kernel_url, method='POST', body=json_encode({})) + response = await gateway_request( + kernel_url, method='POST', headers={'Content-Type': 'application/json'}, body=json_encode({}) + ) self.log.debug("Interrupt kernel response: %d %s", response.code, response.reason) def shutdown_all(self, now=False): From 5ab8717fec27f9110e0a1a7c98017ebe402ff7cc Mon Sep 17 00:00:00 2001 From: faucct Date: Wed, 31 Mar 2021 09:40:29 +0700 Subject: [PATCH 2/2] Merging headers in load_connection_args --- notebook/gateway/managers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/notebook/gateway/managers.py b/notebook/gateway/managers.py index 7674b9ee46..945e51cf2b 100644 --- a/notebook/gateway/managers.py +++ b/notebook/gateway/managers.py @@ -299,7 +299,13 @@ def load_connection_args(self, **kwargs): if len(self._static_args) == 0: self.init_static_args() - kwargs.update(self._static_args) + for arg, static_value in self._static_args.items(): + if arg == 'headers': + given_value = kwargs.setdefault(arg, {}) + if isinstance(given_value, dict): + given_value.update(static_value) + else: + kwargs[arg] = static_value return kwargs