How to use the astroquery.exceptions.RemoteServiceError function in astroquery

To help you get started, we’ve selected a few astroquery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github astropy / astroquery / astroquery / alma / core.py View on Github external
"the file URLs directly with download_files.")
        response.raise_for_status()

        if 'j_spring_cas_security_check' in response.url:
            time.sleep(1)
            # CANNOT cache this stage: it not a real data page!  results in
            # infinite loops
            response = self._request('POST', url, data=payload,
                                     timeout=self.TIMEOUT, cache=False)
            self._staging_log['initial_response'] = response
            if 'j_spring_cas_security_check' in response.url:
                log.warning("Staging request was not successful.  Try again?")
            response.raise_for_status()

        if 'j_spring_cas_security_check' in response.url:
            raise RemoteServiceError("Could not access data.  This error "
                                     "can arise if the data are private and "
                                     "you do not have access rights or are "
                                     "not logged in.")

        request_id = response.url.split("/")[-2]
        self._staging_log['request_id'] = request_id
        log.debug("Request ID: {0}".format(request_id))

        # Submit a request for the specific request ID identified above
        submission_url = urljoin(self.dataarchive_url,
                                 url_helpers.join('rh/submission', request_id))
        log.debug("Submission URL: {0}".format(submission_url))
        self._staging_log['submission_url'] = submission_url
        staging_submission = self._request('GET', submission_url, cache=True)
        self._staging_log['staging_submission'] = staging_submission
        staging_submission.raise_for_status()
github astropy / astroquery / astroquery / alma / core.py View on Github external
size, unit = re.search(r'([0-9\.]*)([A-Za-z]*)',
                                       tds[3].text).groups()
                columns['uid'].append(uid)
                columns['URL'].append(href.attrs['href'])
                unit = (u.Unit(unit) if unit in ('GB', 'MB')
                        else u.Unit('kB') if 'kb' in unit.lower()
                        else 1)
                columns['size'].append(float(size) * u.Unit(unit))
                log.log(level=5, msg="Found an old-style entry.  "
                        "size={0} uid={1} url={2}".format(size, uid,
                                                          columns['URL'][-1]))

        columns['size'] = u.Quantity(columns['size'], u.Gbyte)

        if len(columns['uid']) == 0:
            raise RemoteServiceError(
                "No valid UIDs were found in the staged data table. "
                "Please include {0} in a bug report."
                .format(self._staging_log['data_list_url']))

        tbl = Table([Column(name=k, data=v) for k, v in iteritems(columns)])

        return tbl
github astropy / astroquery / astroquery / alma / core.py View on Github external
cache=cache and not get_html_version)
        self._last_response = response
        response.raise_for_status()

        if get_html_version:
            if 'run' not in response.text:
                if max_retries > 0:
                    log.info("Failed query.  Retrying up to {0} more times"
                             .format(max_retries))
                    return self.query_async(payload=payload, cache=False,
                                            public=public, science=science,
                                            max_retries=max_retries-1,
                                            get_html_version=get_html_version,
                                            get_query_payload=get_query_payload,
                                            **kwargs)
                raise RemoteServiceError("Incorrect return from HTML table query.")
            response2 = self._request('GET',
                                      "{0}/{1}/{2}".format(
                                          self._get_dataarchive_url(), 'aq',
                                          response.text),
                                      params={'query_url':
                                              response.url.split("?")[-1]},
                                      timeout=self.TIMEOUT,
                                      cache=False,
                                      )
            self._last_response = response2
            response2.raise_for_status()
            if len(response2.text) == 0:
                if max_retries > 0:
                    log.info("Failed (empty) query.  Retrying up to {0} more times"
                             .format(max_retries))
                    return self.query_async(payload=payload, cache=cache,
github astropy / astroquery / astroquery / ned / core.py View on Github external
-------
        table : `astropy.table.Table`

        """
        if not verbose:
            commons.suppress_vo_warnings()
        try:
            tf = six.BytesIO(response.content)
            first_table = votable.parse(tf, pedantic=False).get_first_table()
            table = first_table.to_table(use_names_over_ids=True)
            return table
        except Exception as ex:
            (is_valid, err_msg) = _check_ned_valid(response.content)
            if not is_valid:
                if err_msg:
                    raise RemoteServiceError(
                        "The remote service returned the following error "
                        "message.\nERROR: {err_msg}".format(err_msg=err_msg))
                else:
                    raise RemoteServiceError(
                        "The remote service returned an error, but with no "
                        "message.")
            else:
                self.response = response
                self.table_parse_error = ex
                raise TableParseError(
                    "Failed to parse NED result! The raw response can be "
                    "found in self.response, and the error in "
github astropy / astroquery / astroquery / alma / core.py View on Github external
def _parse_result(self, response, verbose=False):
        """
        Parse a VOtable response
        """
        if not verbose:
            commons.suppress_vo_warnings()

        if 'run?' in response.url:
            if response.text == "":
                raise RemoteServiceError("Empty return.")
            # this is a CSV-like table returned via a direct browser request
            import pandas
            table = Table.from_pandas(pandas.read_csv(StringIO(response.text)))

        else:
            fixed_content = self._hack_bad_arraysize_vofix(response.content)
            tf = six.BytesIO(fixed_content)
            vo_tree = votable.parse(tf, pedantic=False, invalid='mask')
            first_table = vo_tree.get_first_table()
            table = first_table.to_table(use_names_over_ids=True)

        return table
github Stargrazer82301 / CAAPR / CAAPR / CAAPR_AstroMagic / PTS / pts / magic / tools / catalogs.py View on Github external
ned_result = Ned.query_object(name)
        ned_entry = ned_result[0]

        # Get a more common name for this galaxy (sometimes, the name obtained from NED is one starting with 2MASX .., use the PGC name in this case)
        if ned_entry["Object Name"].startswith("2MASX "): gal_name = name
        else: gal_name = ned_entry["Object Name"]

        # Get the redshift
        gal_redshift = ned_entry["Redshift"]
        if isinstance(gal_redshift, np.ma.core.MaskedConstant): gal_redshift = None

        # Get the type (G=galaxy, HII ...)
        gal_type = ned_entry["Type"]
        if isinstance(gal_type, np.ma.core.MaskedConstant): gal_type = None

    except astroquery.exceptions.RemoteServiceError:

        # Set attributes
        gal_name = name
        gal_redshift = None
        gal_type = None

    except astroquery.exceptions.TimeoutError:

        # Set attributes
        gal_name = name
        gal_redshift = None
        gal_type = None

    except:

        # Set attributes
github Stargrazer82301 / CAAPR / CAAPR_AstroMagic / PTS / pts / magic / tools / catalogs.py View on Github external
ned_result = Ned.query_object(name)
        ned_entry = ned_result[0]

        # Get a more common name for this galaxy (sometimes, the name obtained from NED is one starting with 2MASX .., use the PGC name in this case)
        if ned_entry["Object Name"].startswith("2MASX "): gal_name = name
        else: gal_name = ned_entry["Object Name"]

        # Get the redshift
        gal_redshift = ned_entry["Redshift"]
        if isinstance(gal_redshift, np.ma.core.MaskedConstant): gal_redshift = None

        # Get the type (G=galaxy, HII ...)
        gal_type = ned_entry["Type"]
        if isinstance(gal_type, np.ma.core.MaskedConstant): gal_type = None

    except astroquery.exceptions.RemoteServiceError:

        # Set attributes
        gal_name = name
        gal_redshift = None
        gal_type = None

    except astroquery.exceptions.TimeoutError:

        # Set attributes
        gal_name = name
        gal_redshift = None
        gal_type = None

    except:

        # Set attributes
github astropy / astroquery / astroquery / ned / core.py View on Github external
if not verbose:
            commons.suppress_vo_warnings()
        try:
            tf = six.BytesIO(response.content)
            first_table = votable.parse(tf, pedantic=False).get_first_table()
            table = first_table.to_table(use_names_over_ids=True)
            return table
        except Exception as ex:
            (is_valid, err_msg) = _check_ned_valid(response.content)
            if not is_valid:
                if err_msg:
                    raise RemoteServiceError(
                        "The remote service returned the following error "
                        "message.\nERROR: {err_msg}".format(err_msg=err_msg))
                else:
                    raise RemoteServiceError(
                        "The remote service returned an error, but with no "
                        "message.")
            else:
                self.response = response
                self.table_parse_error = ex
                raise TableParseError(
                    "Failed to parse NED result! The raw response can be "
                    "found in self.response, and the error in "