Skip to content

Commit

Permalink
allow PUTing plain text instead of JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
apdavison committed Jan 24, 2024
1 parent 90d75ab commit e5b7b65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nmpi/nmpi_saga.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def update_job(self, job):
log = job_copy.pop("log", None)
job_copy.pop("timestamp_started", None)
response = self._put(f"{self.job_server}{job['resource_uri']}", job_copy)
response2 = self._put(f"{self.job_server}{job['resource_uri']}/log", log)
response2 = self._put(f"{self.job_server}{job['resource_uri']}/log", log, format="text")
response["log"] = log
return response

Expand Down
11 changes: 8 additions & 3 deletions nmpi/nmpi_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,22 @@ def _post(self, resource_uri, data):
else:
return req.json()

def _put(self, resource_uri, data):
def _put(self, resource_uri, data, format="json"):
"""
Updates a resource.
"""
if format == "json":
data = json.dumps(data)
headers = {"content-type": "application/json"}
else:
headers = {"content-type": "text/plain"}
req = requests.put(
resource_uri,
data=json.dumps(data),
data=data,
auth=self.auth,
cert=self.cert,
verify=self.verify,
headers={"content-type": "application/json"},
headers=headers,
)
if not req.ok:
self._handle_error(req)
Expand Down

0 comments on commit e5b7b65

Please sign in to comment.