Skip to content

Commit 30fe395

Browse files
committed
Detect proxy automatically
1 parent 8202139 commit 30fe395

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

licensing/internal.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class HelperMethods:
3737

3838
verify_SSL = True
3939

40+
proxy_experimental = False
41+
4042
@staticmethod
4143
def get_SHA256(string):
4244
"""
@@ -125,9 +127,23 @@ def send_request(method, params):
125127
"""
126128

127129
if HelperMethods.verify_SSL:
128-
return urllib.request.urlopen(HelperMethods.server_address + method, \
130+
req = urllib.request.Request(HelperMethods.server_address + method, \
129131
urllib.parse.urlencode(params)\
130-
.encode("utf-8")).read().decode("utf-8")
132+
.encode("utf-8"))
133+
134+
if HelperMethods.proxy_experimental == True:
135+
proxies = urllib.request.getproxies()
136+
if proxies != {}:
137+
138+
if 'http' in proxies:
139+
req.set_proxy(proxies['http'], 'http')
140+
141+
if 'https' in proxies:
142+
req.set_proxy(proxies['https'], 'https')
143+
144+
else:
145+
return urllib.request.urlopen(req).read().decode("utf-8")
146+
131147
else:
132148
ctx = ssl.create_default_context()
133149
ctx.check_hostname = False

0 commit comments

Comments
 (0)