Getting 403 permission denied when uploading documents to Google Drive using Python

Getting permission error while uploading files

I keep running into a 403 forbidden error whenever I try to upload documents using Python and the gdata library. Here’s my code:

import gdata.docs.data
import gdata.docs.client

docs_client = gdata.docs.client.DocsClient(source="FileUploader")
docs_client.ClientLogin("[email protected]", "password123", docs_client.source)
docs_client.http_client_debug = True

file_source = gdata.data.MediaSource(file_path="c:/uploads/document.docx", content_type="application/msword")
result = docs_client.Upload(file_source, "My Document")

The error message says I don’t have permission to do this operation. Download operations work fine with the same credentials. I’m using a standard Gmail account, not a business one. Has anyone faced this issue before?

I had a similar issue previously. The gdata library is outdated, and Google now requires the Drive API v3, which uses OAuth2 for authentication during uploads. The ClientLogin method you’re currently utilizing is no longer supported, which likely leads to the permission errors you are experiencing. While downloads may continue to function with your existing credentials, switching to the latest Google Drive API with OAuth2 will resolve these errors. Setting up credentials via the Google Cloud Console is necessary, but it greatly enhances security and resolves your permission issues.

Your permission issue is happening because Google killed off the Documents List API that gdata uses. Your credentials still work for downloads, but Google blocked uploads through that old authentication method. You’ll need to switch to Google Drive API v3 with OAuth2. Set up a project in Google Cloud Console, enable the Drive API, and create OAuth2 credentials. Then ditch gdata and use google-api-python-client instead. The OAuth2 flow needs user consent for uploads - that’s why your current setup is failing. Google forced this change when they dumped password authentication for security.

check if u got 2FA on your Google accnt - that messes up the old clientlogin for downloads. also, make sure u use the correct content type: application/vnd.openxmlformats-officedocument.wordprocessingml.document for .docx files, not application/msword. honestly tho, gdata’s kinda dead now, time to migrate.