Skip to content

Commit 53d0af7

Browse files
authored
Merge pull request #130 from equinor/post-params
Support query params in post method
2 parents 2bef8db + fa4eedb commit 53d0af7

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

.flake8

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
exclude =
33
_call_azure_api.py
44
_call_sumo_api.py
5-
_auth.py
5+
_auth.py
6+
test_call_sumo_api.py
7+
test_sumo_thin_client.py
8+
setup.py

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ requires = [
44
"setuptools>=28",
55
"setuptools_scm>=3.2.0",
66
"wheel"
7-
]
7+
]
8+
9+
[tool.black]
10+
line-length = 80

src/sumo/wrapper/sumo_client.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ def get(self, path: str, **params) -> dict:
204204
return response.json()
205205

206206
def post(
207-
self, path: str, blob: bytes = None, json: dict = None
207+
self,
208+
path: str,
209+
blob: bytes = None,
210+
json: dict = None,
211+
params: dict = None,
208212
) -> requests.Response:
209213
"""Performs a POST-request to the Sumo API.
210214
@@ -252,20 +256,26 @@ def post(
252256
raise ValueError("Both blob and json given to post.")
253257

254258
content_type = (
255-
"application/json"
256-
if json is not None
257-
else "application/octet-stream"
259+
"application/octet-stream" if blob else "application/json"
258260
)
261+
content_length = 0
262+
263+
if blob or json:
264+
content_length = len(json) if json else len(blob)
259265

260266
headers = {
261267
"Content-Type": content_type,
262268
"authorization": f"Bearer {token}",
263-
"Content-Length": str(len(json) if json else len(blob)),
269+
"Content-Length": str(content_length),
264270
}
265271

266272
try:
267273
response = requests.post(
268-
f"{self.base_url}{path}", data=blob, json=json, headers=headers
274+
f"{self.base_url}{path}",
275+
data=blob,
276+
json=json,
277+
headers=headers,
278+
params=params,
269279
)
270280
except requests.exceptions.ProxyError as err:
271281
raise_request_error_exception(503, err)

0 commit comments

Comments
 (0)