【问题标题】:Error 403 uploading a file to Google Docs with Python使用 Python 将文件上传到 Google Docs 时出现错误 403
【发布时间】:2011-05-24 21:59:20
【问题描述】:

我在尝试将文件上传到 Google 文档时遇到 403 错误 使用 Python / gdata-2.0.13:

import gdata.docs.data
import gdata.docs.client

client = gdata.docs.client.DocsClient(source="MyUpdater")
client.ClientLogin("mymail@gmail.com", "mykey", client.source);
client.http_client_debug = True

ms = gdata.data.MediaSource(file_path="g:/Python/Utiles/test.doc", content_type="application/msword'")
entry = client.Upload(ms, "Test File")

# Error:
gdata.client.RequestError: Server responded with: 403, <errors xmlns='http://sch
emas.google.com/g/2005'><error><domain>GData</domain><code>ServiceForbiddenExcep
tion</code><internalReason>You do not have permission to perform this operation.
</internalReason></error></errors>
...

我尝试下载文件,没有问题。我使用的是普通的 Gmail 帐户(例如,没有 Google Apps 或付费帐户)。

有什么想法吗? TIA, 巴勃罗

【问题讨论】:

  • googleappsdeveloper.blogspot.com/2011/05/… 这篇博文指出你应该使用可恢复的上传方式上传,并传入 ?convert=false uri 参数。如果你设法让它工作,请告诉我,我有很多没有意义的错误。

标签: python google-docs gdata google-docs-api


【解决方案1】:
import gdata.docs.service
import gdata.docs.data

client = gdata.docs.service.DocsService()
client.ClientLogin("me@gmail.com", 'pass', 'test')

ms = gdata.data.MediaSource(file_path="/home/jake/Desktop/test.txt",
                            content_type=gdata.docs.service.SUPPORTED_FILETYPES['TXT'])
entry = client.Upload(ms, "Test File")

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-17
  • 2012-04-23
  • 1970-01-01
  • 2017-02-11
相关资源
最近更新 更多