Peter
Peter

Reputation: 564

# Python, Upload file in Dropbox using python

Python, how find out the path of Dropbox and upload a file there

I want to upload daily csv file to dropbox account, but I'm getting ValidationError and others.

my code:


#finding the path
import pathlib
import dropbox
import os


# Automation is the name of my folder at dropbox

pathlib.Path.home() / "Automation"

Out[37]: WindowsPath('C:/Users/pb/Automation')



dbx = dropbox.Dropbox('My-token here')
dbx.users_get_current_account()


Out[38]:  FullAccount(account_id='accid', name=Name(given_name='pb', surname='manager', familiar_name='pb', display_name='pb', abbreviated_name='pb'), email='[email protected]', email_verified=True, disabled=False, locale='en', referral_link='https://www.dropbox.com/referrals/codigo', is_paired=False, account_type=AccountType('basic', None), root_info=UserRootInfo(root_namespace_id='1111111111', home_namespace_id='11111111'), profile_photo_url='https://dl-web.dropbox.com/account_photo/get/sssssssssssssssssss', country='US', team=None, team_member_id=None)


# Now trying to see something in the folder, I just want upload file there

response = dbx.files_list_folder(path='user:/pb/automation')
print(response)


for entry in dbx.files_list_folder('https://www.dropbox.com/home/automation').entries:
    print(entry.name)



ValidationError: 'user:/pb/automation' did not match pattern '(/(.|[\r\n])*)?|id:.*|(ns:[0-9]+(/.*)?)'

Upvotes: 0

Views: 321

Answers (1)

Taylor Krusen
Taylor Krusen

Reputation: 1043

That error happens because the path parameter that the API is expecting needs to start with a '/'. It could be called out better in the docs.

Is the Automation folder in the root of your Dropbox directory? If so, then '/automation' should be sufficient for path. Try tinkering with the /files/list_folder endpoint in the Dropbox API explorer until you find the correct path.

Your for loop is likely to throw an error too, though. Are you just trying to loop over the results of the list_folder call? I'd suggest changing to

for entry in response:
    print entry

Upvotes: 1

Related Questions