Skip to content

Commit

Permalink
fixed post request v2 so it uses data instead of params w/ burnettk
Browse files Browse the repository at this point in the history
  • Loading branch information
jasquat committed Oct 24, 2023
1 parent 47aeace commit 026de90
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/connector_http/commands/get_request_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def __init__(self,
basic_auth_password: str | None = None,
attempts: int | None = None,
):
HttpRequestBase.__init__(self, url=url, headers=headers, params=params, basic_auth_username=basic_auth_username, basic_auth_password=basic_auth_password)
HttpRequestBase.__init__(self, url=url, headers=headers, basic_auth_username=basic_auth_username, basic_auth_password=basic_auth_password)

self.params = params or {}

if not isinstance(attempts, int) or attempts < 1 or attempts > 10:
attempts = 1
self.attempts = attempts
Expand Down
11 changes: 11 additions & 0 deletions src/connector_http/commands/post_request_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,16 @@


class PostRequestV2(ConnectorCommand, HttpRequestBase):
def __init__(self,
url: str,
headers: dict[str, str] | None = None,
data: dict[str, str] | None = None,
basic_auth_username: str | None = None,
basic_auth_password: str | None = None,
):
HttpRequestBase.__init__(self, url=url, headers=headers, basic_auth_username=basic_auth_username, basic_auth_password=basic_auth_password)

self.data =data or {}

def execute(self, _config: Any, _task_data: dict) -> ConnectorProxyResponseDict:
return self.run_request(requests.post)
17 changes: 14 additions & 3 deletions src/connector_http/http_request_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ class HttpRequestBase:
def __init__(self,
url: str,
headers: dict[str, str] | None = None,
params: dict[str, str] | None = None,
basic_auth_username: str | None = None,
basic_auth_password: str | None = None,
):
self.url = url
self.headers = headers or {}
self.params = params or {}
self.basic_auth_username = basic_auth_username
self.basic_auth_password = basic_auth_password
self.attempts = 1

self.params: dict | None = None
self.data: dict | None = None

def _create_error_from_exception(self, exception: Exception, http_response: requests.Response | None) -> CommandErrorDict:
return self._create_error(
error_code=exception.__class__.__name__, http_response=http_response, additional_message=str(exception)
Expand Down Expand Up @@ -68,7 +69,17 @@ def log(msg: str) -> None:

try:
log(f"Will call {self.url}")
http_response = request_function(self.url, self.params, headers=self.headers, auth=auth, timeout=300)
arguments = {
"url": self.url,
"headers": self.headers,
"auth": auth,
"timeout": 300,
}
if self.params is not None:
arguments["params"] = self.params
if self.data is not None:
arguments["json"] = self.data
http_response = request_function(**arguments)
log(f"Did call {self.url}")

log("Will parse http_response")
Expand Down

0 comments on commit 026de90

Please sign in to comment.