0

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
4ybaka
  • 2,954
  • 4
  • 16
  • 21
  • What have you researched before posting? The accepted answer for [this duplicate](https://stackoverflow.com/questions/66477468/data-version-control-with-google-drive-remote-googleapiclient-errors-unknownap) is pretty clear in stating that `google-api-python-client` versions 2.0.0-2.0.1 were affected by a bug that causes a similar error and that upgrading to 2.0.2 should resolve it. Have you tried this? What were the results? – esqew Feb 16 '22 at 21:55
  • I saw it but it was due to some issue that was fixed long time ago. – 4ybaka Feb 16 '22 at 21:57
  • arggh, yeah. I mixed policy for package versioning in pip and docker. So I expected that ==2 will be resolved in 2.* but it is exactly 2.0.0. – 4ybaka Feb 16 '22 at 22:07

0 Answers0