Skip to content

Commit

Permalink
Merge pull request #32 from dopplershift/html-warning
Browse files Browse the repository at this point in the history
If TDSCatalog detects html, warn and try an XML link.
  • Loading branch information
dopplershift committed Jun 24, 2015
2 parents 39eddeb + 47d76e7 commit 5aac75c
Show file tree
Hide file tree
Showing 3 changed files with 390 additions and 4 deletions.
20 changes: 16 additions & 4 deletions siphon/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import xml.etree.ElementTree as ET

from .metadata import TDSCatalogMetadata
from .http_util import urlopen
from .http_util import create_http_session, urlopen

log = logging.getLogger("siphon.catalog")
log.setLevel(logging.WARNING)
Expand Down Expand Up @@ -41,11 +41,23 @@ def __init__(self, catalog_url):
# top level server url
self.catalog_url = catalog_url
self.base_tds_url = catalog_url.split('/thredds/')[0]

session = create_http_session()

# get catalog.xml file
xml_fobj = urlopen(catalog_url)
resp = session.get(self.catalog_url)

# If we were given an HTML link, warn about it and try to fix to xml
if 'html' in resp.headers['content-type']:
import warnings
new_url = self.catalog_url.replace('html', 'xml')
warnings.warn('URL %s returned HTML. Changing to: %s' % (self.catalog_url,
new_url))
self.catalog_url = new_url
resp = session.get(self.catalog_url)

# begin parsing the xml doc
tree = ET.parse(xml_fobj)
root = tree.getroot()
root = ET.fromstring(resp.text)
if "name" in root.attrib:
self.catalog_name = root.attrib["name"]
else:
Expand Down
Loading

0 comments on commit 5aac75c

Please sign in to comment.