From d8a6f961d503873e55567950d551dbeff97684ea Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Tue, 10 Jun 2014 13:09:39 -0700 Subject: [PATCH] Rename headers to json_headers for requests (seemed a bit clearer) Also output a more informative http exception --- htsworkflow/submission/encoded.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/htsworkflow/submission/encoded.py b/htsworkflow/submission/encoded.py index 04aff70..aa21aa4 100644 --- a/htsworkflow/submission/encoded.py +++ b/htsworkflow/submission/encoded.py @@ -94,6 +94,7 @@ class ENCODED: self.username = None self.password = None self.contexts = contexts if contexts else ENCODED_CONTEXT + self.json_headers = {'Content-Type': 'application/json'} self.schemas = {} def get_auth(self): @@ -188,9 +189,9 @@ class ENCODED: LOGGER.info('requesting url: {}'.format(url)) # do the request - headers = {'content-type': 'application/json'} + LOGGER.debug('username: %s, password: %s', self.username, self.password) - response = requests.get(url, auth=self.auth, headers=headers, params=kwargs) + response = requests.get(url, auth=self.auth, headers=self.json_headers, params=kwargs) if not response.status_code == requests.codes.ok: LOGGER.error("Error http status: {}".format(response.status_code)) response.raise_for_status() @@ -237,16 +238,17 @@ class ENCODED: """ url = self.prepare_url(obj_id) payload = json.dumps(changes) - response = requests.patch(url, auth=self.auth, data=payload) + response = requests.patch(url, auth=self.auth, headers=self.json_headers, data=payload) if response.status_code != requests.codes.ok: LOGGER.error("Error http status: {}".format(response.status_code)) + LOGGER.error("Response: %s", response.text) response.raise_for_status() return response.json() def put_json(self, obj_id, new_object): url = self.prepare_url(obj_id) payload = json.dumps(new_object) - response = requests.put(url, auth=self.auth, data=payload) + response = requests.put(url, auth=self.auth, headers=self.json_headers, data=payload) if response.status_code != requests.codes.created: LOGGER.error("Error http status: {}".format(response.status_code)) response.raise_for_status() -- 2.30.2