scripts/send-error-report: simple hack to use proxy from the enviroment
PATCH 1/1 scripts/send-error-report: simple hack to use proxy from the enviroment
People behind a proxy couldn't send an error report to an upstream server, this should fix the issue if they use a proxy that doesn't require authentication, and it's correctly exported in the enviroment.
There are probbaly better ways to fix this (urllib2, proxy connect,
a command line option for proxy) but those require more changes than I feel confortable doing now.
--- scripts/send-error-report | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
scripts/send-error-report +21 -6
@@ -8,6 +8,24 @@ import httplib, urllib, os, sys, json +from urllib2 import _parse_proxy as parseproxy + + +def handle_connection(server, data): + params = urllib.urlencode({'data': data}) + headers = {"Content-type": "application/json"} + + if os.environ.get("http_proxy") or os.environ.get("HTTP_PROXY"): + proxy = parseproxy(os.environ.get("http_proxy") or os.environ.get("HTTP_PROXY")) + if proxy[1] or proxy[2]: + raise Exception("http proxies that require authentication are not supported for now.") + conn = httplib.HTTPConnection(proxy[3]) + conn.request("POST", "http://%s/ClientPost/" % server, params, headers) + else: + conn = httplib.HTTPConnection(server) + conn.request("POST", "/ClientPost/", params, headers) + + return conn def sendData(json_file, server):
@@ -45,10 +63,7 @@ def sendData(json_file, server): return try: - params = urllib.urlencode({'data': data}) - headers = {"Content-type": "application/json"} - conn = httplib.HTTPConnection(server) - conn.request("POST", "/ClientPost/", params, headers) + conn = handle_connection(server, data) response = conn.getresponse() print response.status, response.reason res = response.read()
@@ -59,8 +74,8 @@ def sendData(json_file, server): with open("%s.response.html" % json_file, "w") as f: f.write(res) conn.close() - except: - print("Server connection failed") + except Exception as e: + print("Server connection failed: %s" % e) else: print("No data file found.")
Signature · 1 line
1.9.0
Actually I'll send v2 which should work for HTTP Basic Authentication too.
Quoted 64 lines · Stefan Stanacar
People behind a proxy couldn't send an error report to an upstream server, this should fix the issue if they use a proxy that doesn't require authentication, and it's correctly exported in the enviroment.
There are probbaly better ways to fix this (urllib2, proxy connect,
a command line option for proxy) but those require more changes than I feel confortable doing now.Signed-off-by Stefan Stanacar <[email protected]>--- scripts/send-error-report | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)scripts/send-error-report +21
-6@@ -8,6 +8,24 @@ import httplib, urllib, os, sys, json +from urllib2 import _parse_proxy as parseproxy + + +def handle_connection(server, data): + params = urllib.urlencode({'data': data}) + headers = {"Content-type": "application/json"} + + if os.environ.get("http_proxy") or os.environ.get("HTTP_PROXY"): + proxy = parseproxy(os.environ.get("http_proxy") or os.environ.get("HTTP_PROXY")) + if proxy[1] or proxy[2]: + raise Exception("http proxies that require authentication are not supported for now.") + conn = httplib.HTTPConnection(proxy[3]) + conn.request("POST", "http://%s/ClientPost/" % server, params, headers) + else: + conn = httplib.HTTPConnection(server) + conn.request("POST", "/ClientPost/", params, headers) + + return conn def sendData(json_file, server):@@ -45,10 +63,7 @@ def sendData(json_file, server): return try: - params = urllib.urlencode({'data': data}) - headers = {"Content-type": "application/json"} - conn = httplib.HTTPConnection(server) - conn.request("POST", "/ClientPost/", params, headers) + conn = handle_connection(server, data) response = conn.getresponse() print response.status, response.reason res = response.read()@@ -59,8 +74,8 @@ def sendData(json_file, server): with open("%s.response.html" % json_file, "w") as f: f.write(res) conn.close() - except: - print("Server connection failed") + except Exception as e: + print("Server connection failed: %s" % e) else: print("No data file found.")