|
8 | 8 | urlencode, |
9 | 9 | urlparse, |
10 | 10 | ) |
11 | | -from urllib.request import urlopen |
| 11 | +from urllib.request import ( |
| 12 | + Request, |
| 13 | + urlopen, |
| 14 | +) |
12 | 15 |
|
13 | 16 | from galaxy.datatypes import sniff |
14 | 17 | from galaxy.datatypes.registry import Registry |
|
17 | 20 | get_charset_from_http_headers, |
18 | 21 | stream_to_open_named_file, |
19 | 22 | ) |
| 23 | +from galaxy.util.user_agent import get_default_headers |
20 | 24 |
|
21 | 25 | GALAXY_PARAM_PREFIX = "GALAXY" |
22 | 26 | GALAXY_ROOT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) |
@@ -51,15 +55,16 @@ def __main__(): |
51 | 55 | sys.exit("The remote data source application has not sent back a URL parameter in the request.") |
52 | 56 |
|
53 | 57 | # The following calls to urlopen() will use the above default timeout |
| 58 | + headers = get_default_headers() |
54 | 59 | try: |
55 | 60 | if URL_method == "get": |
56 | | - page = urlopen(cur_URL, timeout=DEFAULT_SOCKET_TIMEOUT) |
| 61 | + req = Request(cur_URL, headers=headers) |
57 | 62 | elif URL_method == "post": |
58 | | - page = urlopen( |
59 | | - cur_URL, |
60 | | - urlencode(params["param_dict"]["incoming_request_params"]).encode("utf-8"), |
61 | | - timeout=DEFAULT_SOCKET_TIMEOUT, |
62 | | - ) |
| 63 | + data = urlencode(params["param_dict"]["incoming_request_params"]).encode("utf-8") |
| 64 | + req = Request(cur_URL, data=data, headers=headers) |
| 65 | + else: |
| 66 | + raise Exception("Unknown URL_method specified: %s" % URL_method) |
| 67 | + page = urlopen(req, timeout=DEFAULT_SOCKET_TIMEOUT) |
63 | 68 | except Exception as e: |
64 | 69 | sys.exit("The remote data source application may be off line, please try again later. Error: %s" % str(e)) |
65 | 70 | if max_file_size: |
|
0 commit comments