{"record":{"id":"617aaf11e7a61808","repo":"binary-husky/gpt_academic","slug":"doc-docx","errorCode":null,"errorMessage":"请先将.doc文档转换为.docx文档。","messagePattern":"请先将\\.doc文档转换为\\.docx文档。","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"crazy_functions/Word_Summary.py","lineNumber":30,"sourceCode":"    for index, fp in enumerate(file_manifest):\n        if fp.split(\".\")[-1] == \"docx\":\n            from docx import Document\n            doc = Document(fp)\n            file_content = \"\\n\".join([para.text for para in doc.paragraphs])\n        else:\n            try:\n                import win32com.client\n                word = win32com.client.Dispatch(\"Word.Application\")\n                word.visible = False\n                # 打开文件\n                doc = word.Documents.Open(os.getcwd() + '/' + fp)\n                # file_content = doc.Content.Text\n                doc = word.ActiveDocument\n                file_content = doc.Range().Text\n                doc.Close()\n                word.Quit()\n            except:\n                raise RuntimeError('请先将.doc文档转换为.docx文档。')\n\n        # private_upload里面的文件名在解压zip后容易出现乱码（rar和7z格式正常），故可以只分析文章内容，不输入文件名\n        from crazy_functions.pdf_fns.breakdown_txt import breakdown_text_to_satisfy_token_limit\n        from request_llms.bridge_all import model_info\n        max_token = model_info[llm_kwargs['llm_model']]['max_token']\n        TOKEN_LIMIT_PER_FRAGMENT = max_token * 3 // 4\n        paper_fragments = breakdown_text_to_satisfy_token_limit(txt=file_content, limit=TOKEN_LIMIT_PER_FRAGMENT, llm_model=llm_kwargs['llm_model'])\n        this_paper_history = []\n        for i, paper_frag in enumerate(paper_fragments):\n            i_say = f'请对下面的文章片段用中文做概述，文件名是{os.path.relpath(fp, project_folder)}，文章内容是 ```{paper_frag}```'\n            i_say_show_user = f'请对下面的文章片段做概述: {os.path.abspath(fp)}的第{i+1}/{len(paper_fragments)}个片段。'\n            gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(\n                inputs=i_say,\n                inputs_show_user=i_say_show_user,\n                llm_kwargs=llm_kwargs,\n                chatbot=chatbot,\n                history=[],\n                sys_prompt=\"总结文章。\"","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/Word_Summary.py#L12-L48","documentation":"For files whose extension is not docx, Word_Summary tries to open them through pywin32's Word.Application COM automation. The bare except hides the real error and raises a request to convert .doc to .docx. Therefore it fires for every non-docx path where COM is unavailable or Word cannot open the file, not only for actual .doc files.","triggerScenarios":"Running on Linux/macOS or in Docker without Microsoft Word; pywin32 is not installed; Word is not activated or cannot start headless; os.getcwd()+'/'+fp is not a valid absolute/relative path; the document is protected, corrupt, or not really a .doc.","commonSituations":"Deploying gpt_academic in Docker; uploading legacy .doc files to a server; uppercase .DOC handling; another Word COM instance or dialog blocks Dispatch/Open; insufficient filesystem permissions.","solutions":["Convert the file to .docx before upload, preferably on a machine with Word or with LibreOffice.","On a server, run: soffice --headless --convert-to docx file.doc, then upload the result.","On Windows, install Microsoft Word and pywin32 and ensure Word can open without a modal dialog.","Use os.path.abspath(fp) instead of os.getcwd() + '/' + fp.","Log the original COM exception so the actual cause is visible."],"exampleFix":"# before\ndoc = word.Documents.Open(os.getcwd() + '/' + fp)\n\n# after\ndoc_path = os.path.abspath(fp)\ndoc = word.Documents.Open(doc_path)\n","handlingStrategy":"validation","validationCode":"import sys\next = os.path.splitext(fp.lower())[1]\nif ext != \".docx\":\n    if sys.platform != \"win32\":\n        raise ValueError(\"Convert .doc to .docx before upload on non-Windows systems\")\n    try:\n        import win32com.client  # noqa\n    except ImportError as e:\n        raise ValueError(\"pywin32 is required for .doc support\") from e\n","typeGuard":"def is_supported_word_input(fp: str) -> bool:\n    return os.path.isfile(fp) and os.path.splitext(fp.lower())[1] == \".docx\"\n","tryCatchPattern":"try:\n    yield from 解析docx(...)\nexcept RuntimeError as e:\n    if \"转换为.docx\" in str(e):\n        convert_with_libreoffice_or_prompt_user(fp)\n    else:\n        raise\n","preventionTips":["Upload .docx instead of legacy .doc whenever possible.","Do not enable COM-based .doc handling on Linux containers.","Use absolute paths for Word Documents.Open.","Log the original COM exception before replacing it."],"tags":["word","docx","pywin32","windows","com"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}