0

I am trying to create a folder in Google Drive with Python API. Here is the function I wrote

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

Here is the Trace:

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'

Everything else is working: read, write, search....Could anyone please help?

Thanks a lot

1 Answer 1

4

You don't need to insert any media body when creating a folder. Remove the line where you instantiate the MediaFileUpload and don't pass a media_body to the insert request.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.