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

BUG: Fix error path in HTTPEndPoint #187

Merged
merged 1 commit into from
Feb 24, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion siphon/http_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def get(self, path, params=None):
"""
resp = self._session.get(path, params=params)
if resp.status_code != 200:
if resp.headers['Content-Type'].startswith('text/html'):
if resp.headers.get('Content-Type', '').startswith('text/html'):
text = resp.reason
else:
text = resp.text
Expand Down
21 changes: 21 additions & 0 deletions siphon/tests/fixtures/gfs-error-no-header
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [Siphon (0.6.1+29.g0a00acf.dirty)]
method: GET
uri: http://thredds.ucar.edu/thredds/ncss/grib/NCEP/GFS/Global_0p5deg/GFS_Global_0p5deg_20180223_1200.grib2?var=u-component_of_wind_isobaric&time=2018-02-23T22%3A28%3A49
response:
body: {string: 'Requested time 2018-02-23T22:28:49Z does not intersect actual
time range 2018-02-26T06:00:00Z - 2018-02-26T06:00:00Z'}
headers:
Access-Control-Allow-Origin: ['*']
Connection: [close]
Date: ['Fri, 23 Feb 2018 23:06:26 GMT']
Server: [Apache]
X-Frame-Options: [SAMEORIGIN]
status: {code: 400, message: '400'}
version: 1
11 changes: 11 additions & 0 deletions siphon/tests/test_http_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ def test_data_query_add():
assert str(dr) == 'foo=bar'


@recorder.use_cassette('gfs-error-no-header')
def test_http_error_no_header():
"""Test getting an error back without Content-Type."""
endpoint = HTTPEndPoint('http://thredds.ucar.edu/thredds/ncss/grib/NCEP/GFS/'
'Global_0p5deg/GFS_Global_0p5deg_20180223_1200.grib2')
query = endpoint.query().variables('u-component_of_wind_isobaric')
query.time(datetime(2018, 2, 23, 22, 28, 49))
with pytest.raises(HTTPError):
endpoint.get_query(query)


class TestEndPoint(object):
"""Test the HTTPEndPoint."""

Expand Down