I have a shared folder on dropbox account that someone has invited me and give me permission to edit this Folder. Now i want to upload some files by using Python on this folder. I have researched about it and found somehow this solution but i am still encountering the following error during the upload process:
API error: UploadError('path', UploadWriteFailed(reason=WriteError('no_write_permission', None), upload_session_id='pid_upload_session:ABIJK9H7KwTsO3NfedGt3Wv8aCWFwQTwR11SJjV4Yzl3SCg'))
Path error: WriteError('no_write_permission', None)
Below is the code I’m currently using. I would greatly appreciate any guidance or clarification on how to properly upload files to a shared folder under these circumstances, as I’m currently stuck at this point.
import dropbox
from dropbox.files import WriteMode
from dropbox.exceptions import ApiError, AuthError
import os
# Dropbox App Configuration
APP_KEY = 'API Key'
APP_SECRET = ''API Secret key"
REFRESH_TOKEN = '<REFRESH_TOKEN>'
# Shared Folder Configuration
SHARED_FOLDER_ID = '12381081779' # Use the ID we got from verification
LOCAL_FILE_PATH = '1.avif'
def upload_to_shared_folder():
try:
# Initialize Dropbox client
dbx = dropbox.Dropbox(
app_key=APP_KEY,
app_secret=APP_SECRET,
oauth2_refresh_token=REFRESH_TOKEN
)
# Construct proper Dropbox path using namespace syntax
file_name = os.path.basename(LOCAL_FILE_PATH)
dropbox_path = f'ns:{SHARED_FOLDER_ID}/{file_name}'
# Upload file with validated path
with open(LOCAL_FILE_PATH, 'rb') as f:
dbx.files_upload(
f.read(),
dropbox_path,
mode=WriteMode('overwrite'),
autorename=True
)
print(f"Successfully uploaded to shared folder: {dropbox_path}")
except AuthError as e:
print(f"Authentication failed: {e}")
except ApiError as e:
print(f"API error: {e.error}")
if e.error.is_path():
print(f"Path error: {e.error.get_path().reason}")
except Exception as e:
print(f"Unexpected error: {e}")
if __name__ == '__main__':
upload_to_shared_folder()