Can't create Google Drive client in python

10 Views Asked by At

I'm migrating script from python 2 to 3. According to migration guidelines for google-api-python-client - no additional changes required in library usage. But when I run the script with next code:

def create_client():
    credentials = ServiceAccountCredentials.from_json_keyfile_name(
        "gdrive_key.json",
        ['https://www.googleapis.com/auth/drive'])
    http = httplib2.Http()
    http = credentials.authorize(http)
    return build('drive', 'v3', http=http)

it fails with an error:

Traceback (most recent call last):
  File "/usr/local/backup/gdrive_client.py", line 17, in list_files
    service = create_client()
  File "/usr/local/backup/gdrive_client.py", line 14, in create_client
    return build('drive', 'v3', http=http)
  File "/usr/local/lib/python3.8/dist-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/googleapiclient/discovery.py", line 273, in build
    content = _retrieve_discovery_doc(
  File "/usr/local/lib/python3.8/dist-packages/googleapiclient/discovery.py", line 387, in _retrieve_discovery_doc
    raise UnknownApiNameOrVersion("name: %s  version: %s" % (serviceName, version))
googleapiclient.errors.UnknownApiNameOrVersion: name: drive  version: v3

I checked sources and it looks totally fine. It expects file locally and it presents in repo. I didn't check installed package sources (I'm not sure if it is possible) but I would expect if pip install command succeeded - package installed successfully. Anyway I run it in docker and recreated image to confirm broken installation is not a problem. What could be a reason?

Modules:

google-api-python-client==2
oauth2client==4
0

There are 0 best solutions below