0

我正在尝试使用 Python API 在 Google Drive 中创建一个文件夹。这是我写的函数

def testCreateDir(self):
    try:
        media_body = MediaFileUpload("ALLFS", mimetype='application/vnd.google-apps.folder', resumable=True)
        body = {
                'title': "ALLFS",
                'mimeType': "application/vnd.google-apps.folder"
        }
        root_folder = self._service.files().insert(body=body, media_body=media_body).execute()

        return root_folder['id']
    except errors.HttpError,error:
        print 'An error occured: %s' % error
        return None

这是跟踪:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "allfs/service/gdrive.py", line 63, in testCreatedir
    media_body = MediaFileUpload("ALLFS", mimetype='application/vnd.google-apps.folder',      
resumable=True)
  File "/Library/Python/2.7/site-packages/oauth2client/util.py", line 120, in  
positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/apiclient/http.py", line 419, in __init__
    fd = open(self._filename, 'rb')
IOError: [Errno 21] Is a directory: 'ALLFS'

其他一切都在工作:阅读,写作,搜索....有人可以帮忙吗?

非常感谢

4

1 回答 1

4

创建文件夹时无需插入任何媒体正文。删除实例化 MediaFileUpload 的行,并且不要将 media_body 传递给插入请求。

于 2013-02-27T20:51:52.813 回答