我正在尝试使用Google的pythonapi客户端库将a public file from Google Drive导出到本地驱动器。你知道吗
我使用的是this script,这是this tutorial的一个改编示例。我已经验证了我的凭据是否正常工作,并且整天都在使用create
和update
方法,没有任何问题。你知道吗
当我从命令行运行python api_demo.py
时,我得到了预期的结果,并将PDF存储到本地驱动器:
aaronpolhamus$ python api_demo.py
Uploaded "hello.txt" (text/plain)
Uploaded "hello.txt" (application/vnd.google-apps.document)
fileId: P110vUov9J9rg2b1XoHMZ3Ssb4Z-FUUPKNQckuyxn_gmo
mimeType: application/pdf
Downloaded "hello.pdf" (application/pdf)
然而,当我进入pythonshell以交互方式工作时,我只是无法运行它。下面是它的样子:
In [1]: DRIVE.files().export(fileId='P110vUov9J9rg2b1XoHMZ3Ssb4Z-FUUPKNQckuyxn_gmo', mimeType='application/pdf').execute()
/Users/aaronpolhamus/anaconda/envs/credijusto/lib/python3.6/site-packages/oauth2client/_helpers.py in positional_wrapper(*args, **kwargs)
131 elif positional_parameters_enforcement == POSITIONAL_WARNING:
132 logger.warning(message)
--> 133 return wrapped(*args, **kwargs)
134 return positional_wrapper
135
/Users/aaronpolhamus/anaconda/envs/credijusto/lib/python3.6/site-packages/googleapiclient/http.py in execute(self, http, num_retries)
838 callback(resp)
839 if resp.status >= 300:
--> 840 raise HttpError(resp, content, uri=self.uri)
841 return self.postproc(resp, content)
842
HttpError: <HttpError 404 when requesting https://www.googleapis.com/drive/v3/files/P110vUov9J9rg2b1XoHMZ3Ssb4Z-FUUPKNQckuyxn_gmo/export?mimeType=application%2Fpdf returned "File not found: P110vUov9J9rg2b1XoHMZ3Ssb4Z-FUUPKNQckuyxn_gmo.">
现在,如果您转到链接,fileId
实际上没有前导P1
。我试着把前两个字符切掉,结果出现了一个500
错误:
In [2]: DRIVE.files().export(fileId='10vUov9J9rg2b1XoHMZ3Ssb4Z-FUUPKNQckuyxn_gmo', mimeType='application/pdf').execute()
HttpError Traceback (most recent call last)
<ipython-input-237-764cc68cfa0e> in <module>()
----> 1 DRIVE.files().export(fileId='10vUov9J9rg2b1XoHMZ3Ssb4Z-FUUPKNQckuyxn_gmo', mimeType='application/pdf').execute()
/Users/aaronpolhamus/anaconda/envs/credijusto/lib/python3.6/site-packages/oauth2client/_helpers.py in positional_wrapper(*args, **kwargs)
131 elif positional_parameters_enforcement == POSITIONAL_WARNING:
132 logger.warning(message)
--> 133 return wrapped(*args, **kwargs)
134 return positional_wrapper
135
/Users/aaronpolhamus/anaconda/envs/credijusto/lib/python3.6/site-packages/googleapiclient/http.py in execute(self, http, num_retries)
838 callback(resp)
839 if resp.status >= 300:
--> 840 raise HttpError(resp, content, uri=self.uri)
841 return self.postproc(resp, content)
842
HttpError: <HttpError 500 when requesting https://www.googleapis.com/drive/v3/files/10vUov9J9rg2b1XoHMZ3Ssb4Z-FUUPKNQckuyxn_gmo/export?mimeType=application%2Fpdf returned "Internal Error">
命令行和交互式案例之间的差异令人费解,因为我可以产生不同的错误,但还没有更接近于真正弄清楚发生了什么。我正在做完全相同的操作,粘贴在终端中打印的值相同的值。你知道吗
代码和示例数据都是公共的。有什么帮助吗?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐