Skip to content

Commit 929be62

Browse files
committed
Use dictionaries for Python Requests form data
1 parent 6f0b9fc commit 929be62

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/targets/python/requests.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ module.exports = function (source, options) {
6262
}
6363
break
6464

65+
case 'application/x-www-form-urlencoded':
66+
if (source.postData.paramsObj) {
67+
code.push('payload = %s', helpers.literalRepresentation(source.postData.paramsObj, opts))
68+
hasPayload = true
69+
break
70+
}
71+
// Otherwise, fall through to treat as plain text:
72+
6573
default: {
6674
const payload = JSON.stringify(source.postData.text)
6775
if (payload) {

test/fixtures/output/python/requests/application-form-encoded.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
url = "http://mockbin.com/har"
44

5-
payload = "foo=bar&hello=world"
5+
payload = {
6+
"foo": "bar",
7+
"hello": "world"
8+
}
69
headers = { "content-type": "application/x-www-form-urlencoded" }
710

811
response = requests.post(url, data=payload, headers=headers)

test/fixtures/output/python/requests/full.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"key": "value"
99
}
1010

11-
payload = "foo=bar"
11+
payload = { "foo": "bar" }
1212
headers = {
1313
"cookie": "foo=bar; bar=baz",
1414
"accept": "application/json",

0 commit comments

Comments
 (0)