Я пытаюсь загрузить кучу zip-файлов на Team Drive через Python API.Странно то, что программа работает, если zip-файл имеет расширение "csv.gz
", но не работает, если расширение ".zip
".Вот код:
from __future__ import print_function
import uuid
from apiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools
from apiclient import errors
from apiclient.http import MediaFileUpload
args = tools.argparser.parse_args()
args.noauth_local_webserver = True
SCOPES = 'https://www.googleapis.com/auth/drive'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store, args)
DRIVE = discovery.build('drive', 'v3', http=creds.authorize(Http()))
def upload_file_to_td_folder(folder_id, fn, mimeType):
body = {'name': fn, 'mimeType': mimeType, 'parents': [folder_id]}
return DRIVE.files().create(body=body, media_body=fn,
supportsTeamDrives=True, fields='id').execute().get('id')
FILE_MIME = 'application/vnd.google-apps.file'
folder_id = "abcdefg"
# file = "data_2018-09-07.csv.gz" this one works!
file = "data_2018-09-07.zip"
upload_file_to_td_folder(folder_id, file, FILE_MIME)
Вот сообщение об ошибке:
Traceback (most recent call last):
File "test_td.py", line 103, in <module>
upload_file_to_td_folder(folder_id, file, FILE_MIME)
File "test_td.py", line 46, in upload_file_to_td_folder
supportsTeamDrives=True, fields='id').execute().get('id')
File "/home/bo/anaconda3/lib/python3.6/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/bo/anaconda3/lib/python3.6/site-packages/googleapiclient/http.py", line 840, in execute
raise HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError:
<HttpError 400 when requesting https://www.googleapis.com/upload/drive/v3/files?supportsTeamDrives=true&fields=id&alt=json&uploadType=multipart
returned "Bad Request">