From 13fe580c26be74e82b7822e73c0a96f1437c587c Mon Sep 17 00:00:00 2001 From: Fr0stM0urne Date: Thu, 28 Mar 2024 16:01:41 +0500 Subject: [PATCH 1/2] Fix JSON parsing for python requests --- src/targets/python/requests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/targets/python/requests.js b/src/targets/python/requests.js index 1938f97..1ae79f9 100644 --- a/src/targets/python/requests.js +++ b/src/targets/python/requests.js @@ -56,7 +56,7 @@ module.exports = function (source, options) { switch (source.postData.mimeType) { case 'application/json': if (source.postData.jsonObj) { - code.push('payload = %s', helpers.literalRepresentation(source.postData.jsonObj, opts)) + code.push('payload = %s', JSON.stringify(source.postData.jsonObj)) jsonPayload = true hasPayload = true } From f87737e0ebf24d3198908ecf211cdd71a5ff8de9 Mon Sep 17 00:00:00 2001 From: Fr0stM0urne Date: Thu, 28 Mar 2024 21:38:03 +0500 Subject: [PATCH 2/2] move JSON.stringify to python helper --- src/targets/python/helpers.js | 2 +- src/targets/python/requests.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/targets/python/helpers.js b/src/targets/python/helpers.js index 46f72d8..a3c5ee7 100644 --- a/src/targets/python/helpers.js +++ b/src/targets/python/helpers.js @@ -77,7 +77,7 @@ module.exports = { if (value === null || value === undefined) { return '' } - return '"' + value.toString().replace(/"/g, '\\"') + '"' + return JSON.stringify(value) } } } diff --git a/src/targets/python/requests.js b/src/targets/python/requests.js index 1ae79f9..1938f97 100644 --- a/src/targets/python/requests.js +++ b/src/targets/python/requests.js @@ -56,7 +56,7 @@ module.exports = function (source, options) { switch (source.postData.mimeType) { case 'application/json': if (source.postData.jsonObj) { - code.push('payload = %s', JSON.stringify(source.postData.jsonObj)) + code.push('payload = %s', helpers.literalRepresentation(source.postData.jsonObj, opts)) jsonPayload = true hasPayload = true }