astropy/astroquery — pull request #285 by keflavich (2014-05-09 08:02:54+00:00)
Title: Eso.data_retrieval: user-unfriendly exception / error message when not logged in

When using the method ``Eso.data_retrieval`` while not being logged in, an ``IndexError`` is raised. It would be better if there was some custom exception raised with a helpful error message. E.g. ``raise NotAuthenticatedError('you have to be logged in to use this service')``. I'm still working on #284 but after that I can do this small change as well if everyone's ok with that.

It follows my ipython session to illustrate this issue:

```python
In [1]: from astroquery.eso import Eso

In [2]: eso = Eso()

In [3]: table = eso.query_instrument('amber', target="Sgr A*")
WARNING: W42: None:2:0: W42: No XML namespace specified [astropy.io.votable.exceptions]
WARNING: W27: None:10:0: W27: COOSYS deprecated in VOTable 1.2 [astropy.io.votable.exceptions]
WARNING: W03: None:12:0: W03: Implictly generating an ID from a name 'ESO Science Archive - AMBER Data Products - Query Result' -> 'ESO_Science_Archive_-_AMBER_Data_Products_-_Query_Result' [astropy.io.votable.exceptions]

In [4]: data_product_id = table[0]['data_products.dp_id']

In [5]: data_files = eso.data_retrieval([data_product_id])
ERROR: IndexError: list index out of range [astroquery.eso.core]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
in ()
----> 1 data_files = eso.data_retrieval([data_product_id])

/home/derdon/repos/python/3rdparty/astroquery/astroquery/eso/core.pyc in data_retrieval(self, datasets)
246 data_download_form = self._activate_form(data_confirmation_form, form_index=-1)
247 root = html.document_fromstring(data_download_form.content)
--> 248 state = root.xpath("//span[@id='requestState']")[0].text
249 while state != 'COMPLETE':
250 time.sleep(2.0)

IndexError: list index out of range

In [6]: eso.login('derdon')
Authenticating derdon on www.eso.org...
Authentication successful!
Out[6]: True

In [7]: table = eso.query_instrument('amber', target="Sgr A*")

In [8]: data_product_id = table[0]['data_products.dp_id']

In [9]: data_files = eso.data_retrieval([data_product_id])
Downloading AMBER.2006-03-14T07:40:03.741.fits.Z...
Done!
```