diff options
-rwxr-xr-x | scripts/send-error-report | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/scripts/send-error-report b/scripts/send-error-report index d23ae27dda..3d1f7a4017 100755 --- a/scripts/send-error-report +++ b/scripts/send-error-report | |||
@@ -7,7 +7,39 @@ | |||
7 | 7 | ||
8 | 8 | ||
9 | 9 | ||
10 | import httplib, urllib, os, sys, json | 10 | import httplib, urllib, os, sys, json, base64 |
11 | from urllib2 import _parse_proxy as parseproxy | ||
12 | |||
13 | |||
14 | def handle_connection(server, data): | ||
15 | params = urllib.urlencode({'data': data}) | ||
16 | headers = {"Content-type": "application/json"} | ||
17 | proxyrequired = False | ||
18 | if os.environ.get("http_proxy") or os.environ.get("HTTP_PROXY"): | ||
19 | proxyrequired = True | ||
20 | # we need to check that the server isn't a local one, as in no_proxy | ||
21 | try: | ||
22 | temp = httplib.HTTPConnection(server, strict=True, timeout=5) | ||
23 | temp.request("GET", "/") | ||
24 | tempres = temp.getresponse() | ||
25 | if tempres.status == 200: | ||
26 | proxyrequired = False | ||
27 | temp.close() | ||
28 | except: | ||
29 | pass | ||
30 | |||
31 | if proxyrequired: | ||
32 | proxy = parseproxy(os.environ.get("http_proxy") or os.environ.get("HTTP_PROXY")) | ||
33 | if proxy[1] and proxy[2]: | ||
34 | auth = base64.encodestring("%s:%s" % (proxy[1], proxy[2])) | ||
35 | headers["Authorization"] = "Basic %s" % auth | ||
36 | conn = httplib.HTTPConnection(proxy[3]) | ||
37 | conn.request("POST", "http://%s/ClientPost/" % server, params, headers) | ||
38 | else: | ||
39 | conn = httplib.HTTPConnection(server) | ||
40 | conn.request("POST", "/ClientPost/", params, headers) | ||
41 | |||
42 | return conn | ||
11 | 43 | ||
12 | 44 | ||
13 | def sendData(json_file, server): | 45 | def sendData(json_file, server): |
@@ -45,10 +77,7 @@ def sendData(json_file, server): | |||
45 | return | 77 | return |
46 | 78 | ||
47 | try: | 79 | try: |
48 | params = urllib.urlencode({'data': data}) | 80 | conn = handle_connection(server, data) |
49 | headers = {"Content-type": "application/json"} | ||
50 | conn = httplib.HTTPConnection(server) | ||
51 | conn.request("POST", "/ClientPost/", params, headers) | ||
52 | response = conn.getresponse() | 81 | response = conn.getresponse() |
53 | print response.status, response.reason | 82 | print response.status, response.reason |
54 | res = response.read() | 83 | res = response.read() |
@@ -59,8 +88,8 @@ def sendData(json_file, server): | |||
59 | with open("%s.response.html" % json_file, "w") as f: | 88 | with open("%s.response.html" % json_file, "w") as f: |
60 | f.write(res) | 89 | f.write(res) |
61 | conn.close() | 90 | conn.close() |
62 | except: | 91 | except Exception as e: |
63 | print("Server connection failed") | 92 | print("Server connection failed: %s" % e) |
64 | 93 | ||
65 | else: | 94 | else: |
66 | print("No data file found.") | 95 | print("No data file found.") |