Skip to content

Commit

Permalink
improve handling of plain text in send web request block
Browse files Browse the repository at this point in the history
  • Loading branch information
Bentlybro committed Jan 8, 2025
1 parent 7ec9830 commit 9e40f4e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions autogpt_platform/backend/backend/blocks/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,24 @@ def __init__(self):
)

def run(self, input_data: Input, **kwargs) -> BlockOutput:
if isinstance(input_data.body, str):
input_data.body = json.loads(input_data.body)

body = input_data.body

if input_data.json_format:
if isinstance(body, str):
try:
# Try to parse as JSON first
body = json.loads(body)
except json.JSONDecodeError:
# If it's not valid JSON and just plain text,
# we should send it as plain text instead
input_data.json_format = False

response = requests.request(
input_data.method.value,
input_data.url,
headers=input_data.headers,
json=input_data.body if input_data.json_format else None,
data=input_data.body if not input_data.json_format else None,
json=body if input_data.json_format else None,
data=body if not input_data.json_format else None,
)
result = response.json() if input_data.json_format else response.text

Expand Down

0 comments on commit 9e40f4e

Please sign in to comment.