def query(query, authenticate=False, json=False, full_output=False, **kwargs):
"""
Execute a synchronous TAP query to the ESA Gaia database.
:param query:
The TAP query to execute.
:param authenticate: [optional]
Authenticate with the username and password information stored in the
config.
:param json: [optional]
Return the data in JSON format. If set to False, then the data will be
returned as an `astropy.table.Table`.
:param full_output: [optional]
Return a two-length tuple containing the data and the corresponding
`requests.response` object.
:returns:
The data returned - either as an astropy table or a dictionary (JSON) -
and optionally, the `requests.response` object used.
"""
format = "json" if json else "votable"
params = dict(REQUEST="doQuery", LANG="ADQL", FORMAT=format, query=query)
params.update(kwargs)
# Create session.
session = requests.Session()
if authenticate:
utils.login(session)
response = session.get("{}/tap/sync".format(config.url), params=params)
if not response.ok:
raise TAPQueryException(response)
if json:
data = response.json()
else:
# Take the table contents and return an astropy table.
data = Table.read(StringIO(response.text), format="votable")
return (data, response) if full_output else data
评论列表
文章目录