Skip to content

Commit c003f65

Browse files
committed
Add support for insecureSkipVerify with Python
1 parent ed6a9fc commit c003f65

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/targets/python/python3.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,25 @@ module.exports = function (source, options) {
1616
const code = new CodeBuilder()
1717
// Start Request
1818
code.push('import http.client')
19-
.blank()
19+
20+
if (options.insecureSkipVerify) {
21+
code.push('import ssl')
22+
}
23+
24+
code.blank()
2025

2126
// Check which protocol to be used for the client connection
2227
const protocol = source.uriObj.protocol
2328
if (protocol === 'https:') {
24-
code.push('conn = http.client.HTTPSConnection("%s")', source.uriObj.host)
25-
.blank()
29+
if (options.insecureSkipVerify) {
30+
code.push(
31+
'conn = http.client.HTTPSConnection("%s", context = ssl._create_unverified_context())',
32+
source.uriObj.host
33+
).blank()
34+
} else {
35+
code.push('conn = http.client.HTTPSConnection("%s")', source.uriObj.host)
36+
.blank()
37+
}
2638
} else {
2739
code.push('conn = http.client.HTTPConnection("%s")', source.uriObj.host)
2840
.blank()

test/targets/python/python3.js

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

33
require('should')
44

5-
module.exports = function (snippet, fixtures) {}
5+
module.exports = function (HTTPSnippet, fixtures) {
6+
it('should support insecureSkipVerify', function () {
7+
const result = new HTTPSnippet(fixtures.requests.https).convert('python', 'python3', {
8+
insecureSkipVerify: true
9+
})
10+
11+
result.should.be.a.String()
12+
result.should.eql(`import http.client
13+
import ssl
14+
15+
conn = http.client.HTTPSConnection("mockbin.com", context = ssl._create_unverified_context())
16+
17+
conn.request("GET", "/har")
18+
19+
res = conn.getresponse()
20+
data = res.read()
21+
22+
print(data.decode("utf-8"))`)
23+
})
24+
}

0 commit comments

Comments
 (0)