Skip to content

Commit 541d70a

Browse files
committed
Include galaxy user agent in data source tools
Closes #20833
1 parent 777ec1e commit 541d70a

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/galaxy_test/selenium/test_data_source_tools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
from galaxy.util.unittest_utils import skip_if_site_down
24
from .framework import (
35
managed_history,
@@ -10,6 +12,7 @@
1012
class TestDataSource(SeleniumTestCase, UsesHistoryItemAssertions):
1113
ensure_registered = True
1214

15+
@pytest.mark.skip("Skipping UCSC table direct1 data source test, chromedriver fails captcha")
1316
@selenium_test
1417
@managed_history
1518
@skip_if_site_down("https://genome.ucsc.edu/cgi-bin/hgTables")

tools/data_source/data_source.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
urlencode,
99
urlparse,
1010
)
11-
from urllib.request import urlopen
11+
from urllib.request import (
12+
Request,
13+
urlopen,
14+
)
1215

1316
from galaxy.datatypes import sniff
1417
from galaxy.datatypes.registry import Registry
@@ -17,6 +20,7 @@
1720
get_charset_from_http_headers,
1821
stream_to_open_named_file,
1922
)
23+
from galaxy.util.user_agent import get_default_headers
2024

2125
GALAXY_PARAM_PREFIX = "GALAXY"
2226
GALAXY_ROOT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
@@ -51,15 +55,16 @@ def __main__():
5155
sys.exit("The remote data source application has not sent back a URL parameter in the request.")
5256

5357
# The following calls to urlopen() will use the above default timeout
58+
headers = get_default_headers()
5459
try:
5560
if URL_method == "get":
56-
page = urlopen(cur_URL, timeout=DEFAULT_SOCKET_TIMEOUT)
61+
req = Request(cur_URL, headers=headers)
5762
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)
6368
except Exception as e:
6469
sys.exit("The remote data source application may be off line, please try again later. Error: %s" % str(e))
6570
if max_file_size:

0 commit comments

Comments
 (0)