Use curl-cffi with Chrome TLS impersonation, bypassing proxy for FDA. Akamai bot detection blocks requests from proxy/VPN IPs.
(url: str, timeout: int = 30, **kwargs)
| 95 | |
| 96 | @staticmethod |
| 97 | def _cffi_get(url: str, timeout: int = 30, **kwargs) -> Optional[object]: |
| 98 | """Use curl-cffi with Chrome TLS impersonation, bypassing proxy for FDA. |
| 99 | Akamai bot detection blocks requests from proxy/VPN IPs. |
| 100 | """ |
| 101 | if cffi_requests is not None: |
| 102 | saved = {k: os.environ.pop(k, None) for k in ("http_proxy", "https_proxy", "HTTP_PROXY", "HTTPS_PROXY", "all_proxy", "ALL_PROXY")} |
| 103 | try: |
| 104 | session = cffi_requests.Session(impersonate=FDAFetcher.IMPERSONATE) |
| 105 | return session.get(url, timeout=timeout, allow_redirects=True, **kwargs) |
| 106 | finally: |
| 107 | for k, v in saved.items(): |
| 108 | if v is not None: |
| 109 | os.environ[k] = v |
| 110 | return requests.get(url, headers=REQUEST_HEADERS, timeout=timeout, allow_redirects=True, **kwargs) |
| 111 | |
| 112 | @staticmethod |
| 113 | def discover_pdf_url(source_url: str) -> Optional[str]: |
no test coverage detected