POST with json data
= json.dumps(payload).encode("utf-8")
json_as_bytes = request.Request(self.api_url, data=json_as_bytes)
request_object "Content-Type", "application/json")
request_object.add_header("Authorization", f"Bearer {self.token}")
request_object.add_header(try:
with request.urlopen(request_object) as response:
= json.loads(response.read())
res_json except HTTPError as e:
_logger.exception(e.code)
_logger.exception(e.read())raise e
See Also: urllib2 doc