Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow redirects in catalog references #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions thredds_crawler/crawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def request_xml(url, auth=None):
'''
try:
r = requests.get(url, auth=auth, verify=False)
return r.text.encode('utf-8')
return r.url, r.text.encode('utf-8')
except BaseException:
logger.error("Skipping %s (error parsing the XML)" % url)
return
Expand Down Expand Up @@ -216,8 +216,8 @@ def _run(self, url, auth):
url = self._get_catalog_url(url)

# Get an etree object
xml_content = request_xml(url, auth)
for ds in self._build_catalog(url, xml_content):
redirected_url, xml_content = request_xml(url, auth)
for ds in self._build_catalog(redirected_url, xml_content):
yield ds

def _build_catalog(self, url, xml_content):
Expand All @@ -239,7 +239,9 @@ def _build_catalog(self, url, xml_content):

# This is essentially the graph traversal step
for i, response in enumerate(responses):
for ds in self._build_catalog(references[i], response):
redirected_url = response[0]
xml_content = response[1]
for ds in self._build_catalog(redirected_url, xml_content):
yield ds

# Yield the leaves
Expand Down