2014-08-28 154 views
1

我希望能够上传文件在我的硬盘到谷歌驱动器使用计划如下:无法将文件上传到谷歌驱动器

from pydrive.auth import GoogleAuth 
from pydrive.drive import GoogleDrive 

gauth = GoogleAuth() 
drive = GoogleDrive(gauth) 
this_file = 'apple.txt' 
this_file.Upload() 

但是,我得到了以下错误:

AttributeError: 'str' object has no attribute 'Upload' 

我该如何上传?

+0

this_file是一个字符串。不知道你如何使用这个api,但是你在复制什么样的例子? – weston 2014-08-28 23:38:11

+0

http://pythonhosted.org/PyDrive/quickstart.html#creating-and-updating-file – Taylor 2014-08-29 03:55:29

回答

2

示例here说要做到这一点:

this_file = drive.CreateFile() 
this_file.SetContentFile('apple.txt') # Read file and set it as a content of this instance. 
this_file.Upload() # Upload it 
+0

太棒了,如果我有15分,就会+1。尽管如此,接受。 – Taylor 2014-08-29 08:45:34

+0

@泰勒刚刚复出时,你做:D – weston 2014-08-29 08:47:03

0

您正尝试上传一个字符串。 你应该创建一个文件流,然后调用它的上传方法。

this_file =打开( “apple.txt”, “R”) this_file.Upload()

+0

感谢您的回答。但是,我得到了以下错误AttributeError:'文件'对象没有属性'上传' – Taylor 2014-08-28 23:45:19

相关问题