add the json content type header automatically if data is set since we only support json data at the moment w/ burnettk

This commit is contained in:
jasquat 2024-06-12 11:08:32 -04:00
parent 31e76be874
commit 9d03aa6630
No known key found for this signature in database
1 changed files with 4 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import json
import time
from collections.abc import Callable
from typing import Any
import requests # type: ignore
import xmltodict
@ -71,7 +72,7 @@ class HttpRequestBase:
try:
log(f"Will call {self.url}")
arguments = {
arguments: dict[str, Any] = {
"url": self.url,
"headers": self.headers,
"auth": auth,
@ -80,6 +81,8 @@ class HttpRequestBase:
if self.params is not None:
arguments["params"] = self.params
if self.data is not None:
if not arguments["headers"].keys().include("Content-Type", "Content-type"):
arguments["headers"]["Content-Type"] = "application/json"
arguments["json"] = self.data
http_response = request_function(**arguments)
log(f"Did call {self.url}")