Skip to content

Commit

Permalink
Merge pull request #970 from keflavich/eso_sep2017
Browse files Browse the repository at this point in the history
Fix ESO
  • Loading branch information
keflavich committed Sep 8, 2017
2 parents 3e137a3 + 7473254 commit 22ec8d2
Show file tree
Hide file tree
Showing 5 changed files with 368 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -4,6 +4,7 @@
- MAST: Added convenience function to list available missions. [#947]
- SIMBAD: adding 'get_query_payload' kwarg to all public methods to return
the request parameters. [#962]
- ESO: The upstream API changed. We have adapted. [#970]


0.3.6 (2017-07-03)
Expand Down
34 changes: 21 additions & 13 deletions astroquery/eso/core.py
Expand Up @@ -230,19 +230,32 @@ def _login(self, username=None, store_password=False,
password = password_from_keyring
# Authenticate
log.info("Authenticating {0} on www.eso.org...".format(username))

# Do not cache pieces of the login process
login_response = self._request("GET", "https://www.eso.org/sso/login",
cache=False)
# login form: method=post action=login [no id]
login_result_response = self._activate_form(
login_response, form_index=-1, inputs={'username': username,
'password': password})
root = BeautifulSoup(login_response.content, 'html5lib')
login_input = root.find(name='input', attrs={'name': 'execution'})
if login_input is None:
raise ValueError("ESO login page did not have the correct attributes.")
execution = login_input.get('value')

login_result_response = self._request("POST", "https://www.eso.org/sso/login",
data={'username': username,
'password': password,
'execution': execution,
'_eventId': 'submit',
'geolocation': '',
})
login_result_response.raise_for_status()
root = BeautifulSoup(login_result_response.content, 'html5lib')
authenticated = not root.select('.error')
authenticated = root.find('h4').text == 'Login successful'

if authenticated:
log.info("Authentication successful!")
else:
log.exception("Authentication failed!")

# When authenticated, save password in keyring if needed
if authenticated and password_from_keyring is None and store_password:
keyring.set_password("astroquery:www.eso.org", username, password)
Expand Down Expand Up @@ -396,11 +409,7 @@ def query_instrument(self, instrument, column_filters={}, columns=[],
"""

if instrument in ('feros', 'harps', 'grond'):
url = 'http://archive.eso.org/wdb/wdb/eso/eso_archive_main/form'
else:
url = ("http://archive.eso.org/wdb/wdb/eso/{0}/form"
.format(instrument))
url = 'http://archive.eso.org/wdb/wdb/eso/eso_archive_main/form'
table = None
if open_form:
webbrowser.open(url)
Expand All @@ -418,8 +427,7 @@ def query_instrument(self, instrument, column_filters={}, columns=[],
# acquisition
query_dict['tab_dp_id'] = kwargs.pop('tab_dp_id', 'on')

if instrument in ('feros', 'harps', 'ground'):
query_dict['instrument'] = instrument.upper()
query_dict['instrument'] = instrument.upper()

for k in columns:
query_dict["tab_" + k] = True
Expand Down Expand Up @@ -685,7 +693,7 @@ def query_apex_quicklooks(self, project_id=None, help=False,
Examples
--------
>>> tbl = Eso.query_apex_quicklooks('E-093.C-0144A')
>>> tbl = Eso.query_apex_quicklooks('093.C-0144')
>>> files = Eso.retrieve_data(tbl['Product ID'])
"""

Expand Down

0 comments on commit 22ec8d2

Please sign in to comment.