Closed drscotthawley closed 2 years ago
can you try specifying mimeType ?
from pydrive2.auth import GoogleAuth
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
id = "1bwgUL14KCHbBDZErUPScLNYAjb_elb_5pnzHxNyNxY0"
gd_file = drive.CreateFile({'id': id})
gd_file.GetContentFile('spreadsheet.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
I am new at Github, so i am not getting correct way to start issue, if it seems that i face same trouble, discussed in closed issue, so i write here, correct me if i am wrong.
so this is code i use to collect tracebakcs, it gets "mimetype" from Listfile(), when i ise "for item in file_list" it is in item['mimeType'].
def getfile(fileid, filename, mimetype):
try:
file = go.CreateFile({'id': fileid})
file.GetContentFile(f"{save_path}/{filename}", f"{mimetype}") #, chunksize=26214400
print(f"ok {filename}, {mimetype}")
except:
print(f"no, {filename}, {mimetype}")
with open("traceback.txt", "a", encoding='utf-8') as file:
file.write(f"{filename}, {mimetype} _______________________________________________________________")
with open("traceback.txt", "a", encoding='utf-8') as file:
file.write(traceback.format_exc())
so i do send mimetype, the only differ i see is, that my filename does not have ".xlsx" at the end. Code works for all types of files except Google, spreadsheets, docs, maps... So here comes traceback, i removed the function name and etc, to make it more laconic:
readme, application/vnd.google-apps.document _______________________________________________________________Traceback (most recent call last):
googleapiclient.errors.HttpError: <HttpError 403 "Only files with binary content can be downloaded. Use Export with Docs Editors files.". Details: "[{'domain': 'global', 'reason': 'fileNotDownloadable', 'message': 'Only files with binary content can be downloaded. Use Export with Docs Editors files.', 'locationType': 'parameter', 'location': 'alt'}]">
googleapiclient.errors.HttpError: <HttpError 400 "The requested conversion is not supported.". Details: "[{'domain': 'global', 'reason': 'badRequest', 'message': 'The requested conversion is not supported.', 'locationType': 'parameter', 'location': 'convertTo'}]">
pydrive2.files.ApiRequestError: <HttpError 400 "The requested conversion is not supported.". Details: "[{'domain': 'global', 'reason': 'badRequest', 'message': 'The requested conversion is not supported.', 'locationType': 'parameter', 'location': 'convertTo'}]">
testspreadsheet, application/vnd.google-apps.spreadsheet _______________________________________________________________Traceback (most recent call last):
googleapiclient.errors.HttpError: <HttpError 403 "Only files with binary content can be downloaded. Use Export with Docs Editors files.". Details: "[{'domain': 'global', 'reason': 'fileNotDownloadable', 'message': 'Only files with binary content can be downloaded. Use Export with Docs Editors files.', 'locationType': 'parameter', 'location': 'alt'}]">
googleapiclient.errors.HttpError: <HttpError 400 "The requested conversion is not supported.". Details: "[{'domain': 'global', 'reason': 'badRequest', 'message': 'The requested conversion is not supported.', 'locationType': 'parameter', 'location': 'convertTo'}]">
pydrive2.files.ApiRequestError: <HttpError 400 "The requested conversion is not supported.". Details: "[{'domain': 'global', 'reason': 'badRequest', 'message': 'The requested conversion is not supported.', 'locationType': 'parameter', 'location': 'convertTo'}]">
Teriberka, application/vnd.google-apps.map _______________________________________________________________Traceback (most recent call last):
googleapiclient.errors.HttpError: <HttpError 403 "Only files with binary content can be downloaded. Use Export with Docs Editors files.". Details: "[{'domain': 'global', 'reason': 'fileNotDownloadable', 'message': 'Only files with binary content can be downloaded. Use Export with Docs Editors files.', 'locationType': 'parameter', 'location': 'alt'}]">
googleapiclient.errors.HttpError: <HttpError 400 "Export only supports Docs Editors files.". Details: "[{'domain': 'global', 'reason': 'badRequest', 'message': 'Export only supports Docs Editors files.'}]">
pydrive2.files.ApiRequestError: <HttpError 400 "Export only supports Docs Editors files.". Details: "[{'domain': 'global', 'reason': 'badRequest', 'message': 'Export only supports Docs Editors files.'}]">
so fist comes file name, next goes mimetype...
What am i doing wrong, please help...
@shcheklein @MateoWartelle @drscotthawley @tasdomas @rlamy
Hi folks. Thanks for your work on this. I'm trying to download file content using GetContent. The file I'm trying to get is a Google Sheets file from its sharing URL ("Anyone with the link can view"). But apparently pyDrive2 is trying to request it as a text file instead of just downloading it. And this generates an error about "only binary files can be downloaded." Uh....? I just want to download a file programmatically, without having to manually use the Export button. If you don't try to convert to text, it should work (e.g. I can do this via
wget
orcurl
no problem), but pydrive2 seems to be trying to get it to be converted to a text file?The url in question is https://docs.google.com/spreadsheets/d/1bwgUL14KCHbBDZErUPScLNYAjb_elb_5pnzHxNyNxY0/edit?usp=sharing
From which I get the
id = "1bwgUL14KCHbBDZErUPScLNYAjb_elb_5pnzHxNyNxY0"
.Then I run
and that's when the error occurs:
Is this an issue related to BOM? I didn't understand that part of the docs or the example. I might just use
wget
since that works fine, but it'd be nice to stay in pydrive2.Thanks!