【发布时间】:2016-12-09 00:53:58
【问题描述】:
我是一个相当新的 python 用户,我正在尝试使用 Pythonanywhere 将文件上传到 Google Drive。我已经在我的 PC 上成功尝试了我的脚本(如下),但是当我在 Pythonanywhere 上尝试它时出现错误。
部分脚本:
from pydrive.drive import GoogleDrive
def sendtogoogle():
drive = GoogleDrive()
gpath = 'Myfolder'
fname = 'Apicture.jpg'
file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
for file1 in file_list:
if file1['title'] == gpath:
id = file1['id']
file1 = drive.CreateFile({'title': fname, "parents": [{"kind": "drive#fileLink","id": id}]})
file1.SetContentFile(fname)
file1.Upload()
错误:
Traceback (most recent call last):
from pydrive.drive import GoogleDrive
File "/home/myusername/.local/lib/python2.7/site-packages/pydrive/drive.py", line 2, in <module>
from .files import GoogleDriveFile
File "/home/myusername/.local/lib/python2.7/site-packages/pydrive/files.py", line 4, in <module> from apiclient import errors
File "/usr/local/lib/python2.7/dist-packages/apiclient/__init__.py", line 18, in <module>
from googleapiclient import channel
File "/usr/local/lib/python2.7/dist-packages/googleapiclient/channel.py", line 63, in <module>
from googleapiclient import errors
File "/usr/local/lib/python2.7/dist-packages/googleapiclient/errors.py", line 26, in <module>
from oauth2client import util
ImportError: cannot import name util
提前感谢您的任何建议。
【问题讨论】:
标签: python upload google-drive-api pythonanywhere