{"record":{"id":"b5032667703b9bc4","repo":"binary-husky/gpt_academic","slug":"self-doi","errorCode":null,"errorMessage":"无法下载论文 {self.doi}，所有重试都失败了","messagePattern":"无法下载论文 (.+?)，所有重试都失败了","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"crazy_functions/review_fns/data_sources/scihub_source.py","lineNumber":296,"sourceCode":"                    continue\n\n                # 保存PDF文件\n                pdf_name = f\"{self.doi.replace('/', '_').replace(':', '_')}.pdf\"\n                pdf_path = self.path.joinpath(pdf_name)\n                pdf_path.write_bytes(pdf_content)\n\n                logger.info(f\"成功下载论文: {pdf_name}，文件大小: {len(pdf_content)} bytes\")\n                return str(pdf_path)\n\n            except Exception as e:\n                logger.error(f\"第 {attempt + 1} 次尝试失败: {str(e)}\")\n                if attempt < 2:  # 不是最后一次尝试\n                    wait_time = (attempt + 1) * 3  # 递增等待时间\n                    logger.info(f\"等待 {wait_time} 秒后重试...\")\n                    time.sleep(wait_time)\n                continue\n\n        raise Exception(f\"无法下载论文 {self.doi}，所有重试都失败了\")\n\n# Usage Example\nif __name__ == '__main__':\n    # 创建一个用于保存PDF的目录\n    save_path = Path('./downloaded_papers')\n    save_path.mkdir(exist_ok=True)\n\n    # DOI示例\n    sample_doi = '10.3897/rio.7.e67379'  # 这是一篇Nature的论文DOI\n\n    try:\n        # 初始化SciHub下载器，先尝试使用代理\n        logger.info(\"尝试使用代理模式...\")\n        downloader = SciHub(doi=sample_doi, path=save_path, use_proxy=True)\n\n        # 开始下载\n        result = downloader.fetch()\n        print(f\"论文已保存到: {result}\")","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/review_fns/data_sources/scihub_source.py#L278-L314","documentation":"Top-level retry exhaustion in the SciHub downloader: the download is attempted 3 times (with 3s/6s backoff between), and if every attempt raises, it fails with Exception('无法下载论文 {doi}，所有重试都失败了'). The per-attempt errors are only in logs; the raised message does not include the last cause.","triggerScenarios":"All three attempts hit the failure chain: mirror discovery fails (error 87), all mirrors fail the POST (error 88), PDF link extraction from the returned HTML fails (no #pdf element/iframe), or downloading the extracted PDF content fails — then this exception surfaces from the download-by-DOI entry point.","commonSituations":"Blocked/unstable network to SciHub over the whole retry window; DOI not in SciHub's holdings so every page lacks a PDF element; captcha interstitials on every attempt; proxy timeouts under 30s while SciHub is slow.","solutions":["Read the preceding log lines ('第 N 次尝试失败: ...') to identify which stage fails — mirror, extraction, or PDF fetch.","Test the DOI manually in a browser on a live mirror to confirm SciHub actually has the paper.","Fix the environment: working proxy, updated mirror list, longer timeout.","If the paper is on arXiv, use ArxivSource.download_pdf instead of SciHub."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    pdf = scihub.download(doi, dirpath)\nexcept Exception as e:\n    if '所有重试都失败了' in str(e):\n        logger.warning('SciHub failed for %s, trying open-access sources', doi)\n        pdf = try_open_access(doi)  # arXiv / unpaywall / publisher OA\n        if pdf is None:\n            raise\n    else:\n        raise","preventionTips":["Treat SciHub as best-effort: chain it after legal/open-access sources with a fallback chain.","Check the per-attempt log lines — they carry the root cause the final message omits.","Confirm network/proxy health before retry loops; blind retries against a blocked network waste minutes."],"tags":["scihub","retry","download","doi","network"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}