From d95b4609b0b4912a4b736ca7e20941957a775b45 Mon Sep 17 00:00:00 2001 From: Brian McKeon Date: Tue, 16 Apr 2024 20:30:28 -0400 Subject: [PATCH 1/5] Added content-type header to requests. --- integresql_client_python/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integresql_client_python/__init__.py b/integresql_client_python/__init__.py index 207b578..8ca12be 100644 --- a/integresql_client_python/__init__.py +++ b/integresql_client_python/__init__.py @@ -237,11 +237,12 @@ def request(self, method: str, path: str, *, ) -> requests.Response: path = path.lstrip('/') url = f"{self.base_url}/{self.api_version}/{path}" + headers = {"Content-Type", "application/json"} if self.debug: - print(f"Request {method.upper()} to {url} with qs {qs} and data {payload}", file=sys.stderr) + print(f"Request {method.upper()} to {url} with qs {qs} and headers {headers} and data {payload}", file=sys.stderr) - rsp = self.connection.request(method, url, qs, payload) + rsp = self.connection.request(method, url, qs, payload, headers = headers) if self.debug: print(f"Response from {method.upper()} {url}: [{rsp.status_code}] {rsp.content}", file=sys.stderr) From 3ee5f17b70e7c110df2e76b4a453428894a31d81 Mon Sep 17 00:00:00 2001 From: Brian McKeon Date: Tue, 16 Apr 2024 20:38:51 -0400 Subject: [PATCH 2/5] Fixed typo. --- integresql_client_python/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integresql_client_python/__init__.py b/integresql_client_python/__init__.py index 8ca12be..5ae2c12 100644 --- a/integresql_client_python/__init__.py +++ b/integresql_client_python/__init__.py @@ -237,7 +237,7 @@ def request(self, method: str, path: str, *, ) -> requests.Response: path = path.lstrip('/') url = f"{self.base_url}/{self.api_version}/{path}" - headers = {"Content-Type", "application/json"} + headers = {"content-type": "application/json"} if self.debug: print(f"Request {method.upper()} to {url} with qs {qs} and headers {headers} and data {payload}", file=sys.stderr) From 77f6646af389d330080c9a73143a32884939bed3 Mon Sep 17 00:00:00 2001 From: Brian McKeon Date: Tue, 16 Apr 2024 20:44:46 -0400 Subject: [PATCH 3/5] Convert request data to json. --- integresql_client_python/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/integresql_client_python/__init__.py b/integresql_client_python/__init__.py index 5ae2c12..737b170 100644 --- a/integresql_client_python/__init__.py +++ b/integresql_client_python/__init__.py @@ -2,6 +2,7 @@ import hashlib import http.client +import json import os import pathlib import sys @@ -137,7 +138,7 @@ def __init__(self, integresql: 'IntegreSQL') -> None: self.dbinfo = None def initialize(self) -> 'Template': - rsp = self.integresql.request('POST', '/templates', payload={'hash': str(self.integresql.tpl_hash)}) + rsp = self.integresql.request('POST', '/templates', payload={"hash": str(self.integresql.tpl_hash)}) if rsp.status_code == http.client.OK: self.dbinfo = DBInfo(rsp.json()) return self @@ -238,11 +239,12 @@ def request(self, method: str, path: str, *, path = path.lstrip('/') url = f"{self.base_url}/{self.api_version}/{path}" headers = {"content-type": "application/json"} + json_payload = json.dumps(payload) if self.debug: - print(f"Request {method.upper()} to {url} with qs {qs} and headers {headers} and data {payload}", file=sys.stderr) + print(f"Request {method.upper()} to {url} with qs {qs} and headers {headers} and data {json_payload}", file=sys.stderr) - rsp = self.connection.request(method, url, qs, payload, headers = headers) + rsp = self.connection.request(method, url, qs, json_payload, headers = headers) if self.debug: print(f"Response from {method.upper()} {url}: [{rsp.status_code}] {rsp.content}", file=sys.stderr) From d6ff01d9f7e43e12e4d7d30ea558ccb3d36e813d Mon Sep 17 00:00:00 2001 From: Brian McKeon Date: Tue, 16 Apr 2024 20:53:07 -0400 Subject: [PATCH 4/5] Revert change. --- integresql_client_python/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integresql_client_python/__init__.py b/integresql_client_python/__init__.py index 737b170..b6f7cf5 100644 --- a/integresql_client_python/__init__.py +++ b/integresql_client_python/__init__.py @@ -138,7 +138,7 @@ def __init__(self, integresql: 'IntegreSQL') -> None: self.dbinfo = None def initialize(self) -> 'Template': - rsp = self.integresql.request('POST', '/templates', payload={"hash": str(self.integresql.tpl_hash)}) + rsp = self.integresql.request('POST', '/templates', payload={'hash': str(self.integresql.tpl_hash)}) if rsp.status_code == http.client.OK: self.dbinfo = DBInfo(rsp.json()) return self From 60d94b52faa4de7f5b31ca7f6e345cbdd16d2679 Mon Sep 17 00:00:00 2001 From: Brian McKeon Date: Tue, 16 Apr 2024 20:58:14 -0400 Subject: [PATCH 5/5] Fix to maintain coding style. --- integresql_client_python/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integresql_client_python/__init__.py b/integresql_client_python/__init__.py index b6f7cf5..8f1891b 100644 --- a/integresql_client_python/__init__.py +++ b/integresql_client_python/__init__.py @@ -244,7 +244,7 @@ def request(self, method: str, path: str, *, if self.debug: print(f"Request {method.upper()} to {url} with qs {qs} and headers {headers} and data {json_payload}", file=sys.stderr) - rsp = self.connection.request(method, url, qs, json_payload, headers = headers) + rsp = self.connection.request(method, url, qs, json_payload, headers=headers) if self.debug: print(f"Response from {method.upper()} {url}: [{rsp.status_code}] {rsp.content}", file=sys.stderr)