Beispiel #1
0
def get_pacer_doc_id_with_show_case_doc_url(self, rd_pk, cookies):
    """use the show_case_doc URL to get pacer_doc_id values.

    :param rd_pk: The pk of the RECAPDocument you want to get.
    :param cookies: A requests.cookies.RequestsCookieJar with the cookies of a
    logged-in PACER user.
    """
    rd = RECAPDocument.objects.get(pk=rd_pk)
    d = rd.docket_entry.docket
    s = PacerSession(cookies=cookies)
    pacer_court_id = map_cl_to_pacer_id(d.court_id)
    report = ShowCaseDocApi(pacer_court_id, s)
    last_try = (self.request.retries == self.max_retries)
    try:
        if rd.document_type == rd.ATTACHMENT:
            report.query(d.pacer_case_id, rd.document_number,
                         rd.attachment_number)
        else:
            report.query(d.pacer_case_id, rd.document_number)
    except (ConnectTimeout, ConnectionError, ReadTimeout, ReadTimeoutError,
            ChunkedEncodingError) as exc:
        logger.warning("Unable to get PDF for %s" % rd)
        if last_try:
            return
        else:
            raise self.retry(exc=exc)
    except HTTPError as exc:
        if exc.response.status_code in [
                HTTP_500_INTERNAL_SERVER_ERROR, HTTP_504_GATEWAY_TIMEOUT
        ]:
            if last_try:
                logger.error("Ran into repeated HTTPErrors. No more retries. "
                             "Aborting.")
                return
            else:
                logger.warning("Ran into HTTPError: %s. Retrying." %
                               exc.response.status_code)
                raise self.retry(exc)
        else:
            msg = "Ran into unknown HTTPError. %s. Aborting." % \
                  exc.response.status_code
            logger.error(msg)
            return
    try:
        pacer_doc_id = report.data
    except ParsingException:
        logger.error("Unable to get redirect for %s" % rd)
        return
    else:
        rd.pacer_doc_id = pacer_doc_id
        rd.save()
        logger.info("Successfully saved pacer_doc_id to rd %s" % rd_pk)
Beispiel #2
0
 def setUpClass(cls):
     if pacer_credentials_are_defined():
         cls.report = ShowCaseDocApi("dcd", get_pacer_session())
 def test_bankruptcy_fails(self):
     """Does initializing the API fail on bankruptcy courts?"""
     with self.assertRaises(AssertionError):
         ShowCaseDocApi("caeb", pacer_session=self.pacer_session)
Beispiel #4
0
 def setUpClass(cls):
     if PACER_USERNAME and PACER_PASSWORD:
         cls.pacer_session = PacerSession(username=PACER_USERNAME,
                                          password=PACER_PASSWORD)
         cls.report = ShowCaseDocApi('dcd', cls.pacer_session)