You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

InstaPy运行报错:File is not a zip file问题排查求助

问题:InstaPy自动化脚本运行时出现zipfile.BadZipFile错误

我正在使用InstaPy工具运行自动化脚本,但执行代码时命令提示符(cmd)中出现了错误提示。具体信息如下:

正在使用的工作区:"C:/Users/lggal/InstaPy"

错误回溯信息:

Traceback (most recent call last):
  File "C:\Users\lggal\OneDrive\Área de Trabalho\hastag.py", line 4, in <module>
    session = InstaPy(username='thedesignerofdark', password='Thewitcher2020')
  File "C:\Users\lggal\AppData\Roaming\Python\Python39\site-packages\instapy\instapy.py", line 325, in __init__
    self.browser, err_msg = set_selenium_local_session(
  File "C:\Users\lggal\AppData\Roaming\Python\Python39\site-packages\instapy\browser.py", line 122, in set_selenium_local_session
    driver_path = geckodriver_path or get_geckodriver()
  File "C:\Users\lggal\AppData\Roaming\Python\Python39\site-packages\instapy\browser.py", line 38, in get_geckodriver
    sym_path = gdd.download_and_install()[1]
  File "C:\Users\lggal\AppData\Roaming\Python\Python39\site-packages\webdriverdownloader\webdriverdownloader.py", line 195, in download_and_install
    with zipfile.ZipFile(os.path.join(self.get_download_path(version), filename), mode="r") as driver_zipfile:
  File "C:\Program Files\Python39\lib\zipfile.py", line 1257, in __init__
    self._RealGetContents()
  File "C:\Program Files\Python39\lib\zipfile.py", line 1324, in _RealGetContents
    raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file

请问有人知道该问题的成因及解决方法吗?


解答

问题成因

这个错误的核心是InstaPy自动下载GeckoDriver时获取到的文件并非有效的ZIP压缩包,常见触发原因包括:

  • 网络不稳定导致下载中断,文件下载不完整;
  • 驱动的官方下载源临时出现问题,提供的压缩包本身损坏;
  • 脚本运行权限不足,导致下载的文件写入时不完整;
  • 本地存储路径里的已下载文件被意外篡改。

解决方法

  • 手动下载配置GeckoDriver(最稳妥方案)

    1. 先查看你电脑上Firefox浏览器的版本(打开Firefox,点击右上角菜单→帮助→关于Firefox即可查看);
    2. 下载与浏览器版本完全匹配的GeckoDriver压缩包;
    3. 解压压缩包得到geckodriver.exe文件,把它放到Python的Scripts目录下(你的路径是C:\Program Files\Python39\Scripts),或者将该文件所在路径添加到系统环境变量PATH中;
    4. 重新运行InstaPy脚本,此时工具会直接使用你手动配置好的驱动,不会再自动下载。
  • 清理损坏的自动下载文件
    找到InstaPy自动存储GeckoDriver的路径(一般是C:\Users\lggal\AppData\Roaming\Python\Python39\site-packages\webdriverdownloader下的相关文件夹),删除其中已损坏的ZIP包,然后重新运行脚本,让工具重新完整下载驱动。

  • 确保网络与权限正常

    1. 检查网络连接状态,确保下载过程中不会出现中断;
    2. 右键点击命令提示符,选择「以管理员身份运行」后再执行脚本,避免因权限不足导致文件写入失败。

内容的提问来源于stack exchange,提问作者Lucas Gallani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 18:22:37