astropy / astropy/astroquery

SDSS.query_region() returns misleading Table containing HTML error

Open
#3,369 7 comments 0 reactions 0 assignees View on GitHub
bug sdss
Dominant language
Python
Stars
791
Forks
451
Avg merge
1d 3h
Merged PRs (30d)
4

Description

When calling SDSS.query_region() with valid SkyCoord input, I occasionally receive what appears to be a successful astropy.table.Table response, but the contents are actually an HTML error page from the SDSS server. This causes downstream failures when passed to SDSS.get_spectra() (e.g., KeyError: 'run2d'), which expects real SDSS metadata.
Here’s a minimal working example:

```
from astroquery.sdss import SDSS
from astropy.coordinates import SkyCoord
import astropy.units as u

coord = SkyCoord(ra=148.70583333*u.deg, dec=9.27108333*u.deg)
xid = SDSS.query_region(coord, radius=3*u.arcsec, spectro=True, data_release=18)

print(type(xid)) #
print(xid) # Contains an HTML error page
print(xid.colnames) # ['...']
```
Expected behavior:
If the request failed, xid should be None or an Exception should be raised.

Actual behavior:
An astropy.table.Table is returned, but with HTML content instead of usable columns like 'plate', 'fiberID', 'mjd', etc.
This leads to confusing downstream errors.

Suggested improvement:
Detect HTML responses and raise a proper error (e.g., RemoteServiceError) instead of wrapping them in a Table.
Alternatively, return None or a Table with metadata indicating the failure.

Thanks for maintaining Astroquery — this would really help users handle these cases more cleanly!

Contributor guide

Open the contributing guide

Research direction

Start with SDSS.query_region() and reproduce the provided SkyCoord example using data_release=18. Inspect how the response becomes an astropy.table.Table and how failures are represented. Done means an HTML error response no longer appears as usable SDSS metadata, instead producing the agreed failure behavior, with coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.