3

I am currently trying to convert my python project to an exe with autopytoexe. In my program I use the following code to access a spreadsheet via the 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

Everything works fine as pure python, but not as an exe. I already solved a previous problem with the google-api-python-client with solution 2 here

Unfortunately, I am stuck again. The error message is the following:

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

I already tried to just change the version in the "service" declaration to 'v3', but the error message just changes to v3 then.

This is my first question, pls don't be so hard on me :)

ALZERCODE
  • 47
  • 6

1 Answers1

6

I had the same issue. check this solution: 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)