ALZ*_*ODE 3 python google-sheets google-sheets-api
我目前正在尝试使用 autopytoexe 将我的 python 项目转换为 exe。在我的程序中,我使用以下代码通过 Google Sheet API 访问电子表格:
from googleapiclient.discovery import build
from google.oauth2 import service_account
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
SERVICE_ACCOUNT_FILE = 'keys.json'
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=self.SCOPES)
service = build('sheets', 'v4', credentials=credentials)
sheet = service.spreadsheets()
# read stuff from the sheet after that
Run Code Online (Sandbox Code Playgroud)
一切都可以作为纯 python 正常运行,但不能作为 exe 运行。我已经用解决方案 2 解决了 google-api-python-client 的先前问题
不幸的是,我又被困住了。错误信息如下:
Traceback (most recent call last):
File <my python file in line where "service" is declared>
File "googleapiclient\_helpers.py", line 134, in positional_wrapper
File "googleapiclient\discovery.py", line 291, in build
File "googleapiclient\discovery.py", line 405, in _retrieve_discovery_doc
googleapiclient.errors.UnknownApiNameOrVersion: name: sheets version: v4
Run Code Online (Sandbox Code Playgroud)
我已经尝试将“service”声明中的版本更改为“v3”,但错误消息只是更改为 v3。
这是我的第一个问题,请不要对我这么难:)
我遇到过同样的问题。检查此解决方案: https ://github.com/nithinmurali/pygsheets/issues/490
try:
service = build('sheets', 'v4', credentials=credentials)
except:
DISCOVERY_SERVICE_URL = 'https://sheets.googleapis.com/$discovery/rest?version=v4'
service = build('sheets', 'v4', credentials=credentials, discoveryServiceUrl=DISCOVERY_SERVICE_URL)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1831 次 |
| 最近记录: |