调用send2trash报错:OLE error 0x80270027问题求助
问题描述
在C:\Users\Ken目录下调用send2trash.send2trash('practice.txt')时触发报错,对random.txt执行相同操作也失败,错误信息如下:
尝试从目录
C:\Users\Ken运行send2trash时出现错误。
com_error Traceback (most recent call last) File ~\Anaconda3\lib\site-packages\send2trash\plat_win_modern.py:61, in send2trash(paths) 60 fileop.DeleteItem(item, sink) ---> 61 result = fileop.PerformOperations() 62 aborted = fileop.GetAnyOperationsAborted() com_error: (-2144927705, 'OLE error 0x80270027', None, None) During handling of the above exception, another exception occurred: OSError Traceback (most recent call last) Input In [31], in <cell line: 1>() ----> 1 send2trash.send2trash('practice.txt') File ~\Anaconda3\lib\site-packages\send2trash\plat_win_modern.py:69, in send2trash(paths) 65 raise OSError(None, None, paths, result) 66 except pywintypes.com_error as error: 67 # convert to standard OS error, allows other code to get a 68 # normal errno ---> 69 raise OSError(None, error.strerror, path, error.hresult) 70 finally: 71 # Need to make sure we call this once fore every init 72 pythoncom.CoUninitialize() OSError: [WinError -2144927705] OLE error 0x80270027: 'C:\Users\Ken\Complete-Python-3-Bootcamp-master\12-Advanced Python Modules\practice.txt'
解决方案
错误码0x80270027对应Windows系统的FDE_E_RECYCLEBIN_NOT_AVAILABLE,表示程序无法访问目标路径对应的回收站,以下是常见原因及解决办法:
- 权限不足:当前Python进程无回收站访问权限。右键点击Anaconda Prompt(或你使用的Python IDE),选择「以管理员身份运行」后重新执行代码。
- 回收站损坏:用户目录下的回收站可能损坏。打开
C:\$Recycle.Bin,找到对应用户SID的文件夹(可通过命令行输入whoami /user查看SID),删除该文件夹后重启电脑,系统会自动重建回收站。 - 路径不明确:确认当前工作目录是否为
C:\Users\Ken,可先执行print(os.getcwd())验证;或者改用绝对路径调用:import send2trash import os file_path = os.path.abspath('practice.txt') send2trash.send2trash(file_path) - send2trash版本兼容问题:旧版本可能存在Windows适配bug,升级到最新版本:
pip install --upgrade send2trash - 组策略限制:企业环境下组策略可能禁用回收站功能。按下
Win+R输入gpedit.msc,检查「用户配置→管理模板→Windows组件→文件资源管理器→不要将已删除的文件移动到回收站」是否启用,若启用则改为「未配置」或「禁用」。
内容的提问来源于stack exchange,提问作者Kennedy Ozoani
相关产品推荐
相关产品推荐

