0

my code is uploading a txt file to my drop box, but the document it self is empty of content. It only reading inside the title of the file 'test_data.txt', the data itself which is in the real file is not there. The file never updates either when running the script a second time, but I suspect this is because the file is not being updated (it's not actually reading the contents of the .txt file). If anyone could help me with this I would appreciate it.

import dropbox
from dropbox.files import WriteMode
overwrite = WriteMode('overwrite', None)

token = 'xxxx'

dbx = dropbox.Dropbox(token)
dbx.users_get_current_account()
dbx.files_upload('test_data.txt', '/test_data.txt', mode = WriteMode('overwrite'))

1 Answer 1

1

files_upload should recieve a content to upload. In your current code you are asking to upload string "test_data.txt" as file "/test_data.txt".

with open('test_data.txt', 'rb') as fh:
    dbx.files_upload(fh.read(), '/test_data.txt')
Sign up to request clarification or add additional context in comments.

2 Comments

That worked perfectly for loading the actual data onto Dropbox. I seem to be having a problem with the over write though I think once I try to run it again? Do you know why that is? Here's the error: 39790e91b2e957d2ab8414f990', UploadError(u'path', UploadWriteFailed(reason=WriteError(u'conflict', WriteConflictError(u'file', None)), upload_session_id=u'AAAAAAAAE-y8ZxAODG-lkg')))
use mode=dropbox.files.WriteMode.overwrite param in files_upload

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.