我希望能够使用以下程序将我的硬盘内的文件上传到Google云端硬盘:
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 :(得分: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
答案 1 :(得分:0)
您正在尝试上传字符串。 您应该创建一个文件流,然后在其上调用upload方法。
this_file = open(" apple.txt"," r") this_file.Upload()