【问题标题】:Cannot build the Google Drive API service in an app bundled with PyInstaller无法在与 PyInstaller 捆绑的应用中构建 Google Drive API 服务
【发布时间】:2022-09-25 16:00:40
【问题描述】:

当我使用 PyInstaller 捆绑应用程序时,服务构建方法 (googleapiclient.discovery.build) 在指定 Google Drive 的服务名称及其版本时不会自动工作 我得到这个错误: googleapiclient.errors.UnknownApiNameOrVersion: name: drive version: v3

这是我要重现的代码示例:

from googleapiclient.discovery import build
build(\"drive\", \"v3\", credentials=credentials)

(您需要设置凭据,我使用https://www.googleapis.com/auth/drive 范围)

以下是我使用pyinstaller 命令捆绑我的应用程序的选项:

--onefile --additional-hooks-dir=./hooks

我通过指定 discoveryServiceUrl 参数并将其设置为正确的发现 url 来使其适用于任何其他服务,这应该是 https://SERVICE.googleapis.com/$discovery/rest?version=VERSION (IE https://sheets.googleapis.com/$discovery/rest?version=v4 用于 Google 表格)

但似乎 Google Drive 没有标准的发现 url,我找不到正确的

我尝试使用工作表发现 url 构建驱动器并且构建没有失败,但是我不能使用驱动器 API 方法(如.files()

我还尝试手动添加您可以在那里找到的 googleapiclient 挂钩:https://github.com/pyinstaller/pyinstaller-hooks-contrib/blob/master/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-googleapiclient.model.py (捆绑时应该自动添加)但它也不起作用

你知道让它适用于 Google Drive 的方法吗?我必须改变运行 PyInstaller 的方式吗? 谢谢 !

    标签: python google-api pyinstaller google-api-python-client


    【解决方案1】:

    改变 构建('驱动器','v3',凭证=凭证) 至 构建('驱动器','v3',凭据=凭据,静态发现=假)

    【讨论】:

      猜你喜欢
      • 2018-06-25
      • 1970-01-01
      • 2022-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多