Utility function so that the script can loop over paged results.
(logger, jobs_manager, fb_url, timeout_attempt=0)
| 41 | |
| 42 | |
| 43 | def make_https_request(logger, jobs_manager, fb_url, timeout_attempt=0): |
| 44 | """ |
| 45 | Utility function so that the script can loop over paged results. |
| 46 | """ |
| 47 | try: |
| 48 | req = requests.get(fb_url) |
| 49 | req.raise_for_status() |
| 50 | except requests.exceptions.ConnectionError: |
| 51 | logger.error("FATAL: Connection Error while fetching the cert list") |
| 52 | jobs_manager.record_job_error() |
| 53 | exit(1) |
| 54 | except requests.exceptions.HTTPError: |
| 55 | # This occasionally triggers on false domain names |
| 56 | # For instance, we are holding .web but it isn't officially recognized yet. |
| 57 | # Therefore, Facebook will error on it but it is safe to continue processing. |
| 58 | logger.warning("HTTP Error while fetching the cert list") |
| 59 | return None |
| 60 | except Timeout: |
| 61 | if timeout_attempt == 0: |
| 62 | logger.warning("Timeout occurred. Attempting again...") |
| 63 | result = make_https_request(logger, jobs_manager, fb_url, timeout_attempt=1) |
| 64 | return result |
| 65 | else: |
| 66 | logger.error("FATAL: Too many timeouts. Exiting") |
| 67 | jobs_manager.record_job_error() |
| 68 | exit(1) |
| 69 | except requests.exceptions.RequestException as err: |
| 70 | logger.error("FATAL: Request exception while fetching the cert list") |
| 71 | logger.error(str(err)) |
| 72 | jobs_manager.record_job_error() |
| 73 | exit(1) |
| 74 | |
| 75 | if req.status_code != 200: |
| 76 | return None |
| 77 | |
| 78 | return json.loads(req.text) |
| 79 | |
| 80 | |
| 81 | def fetch_domain(logger, jobs_manager, fbc, access_token, zone): |
no test coverage detected