0

I am making a Python script to upload mp3 files in my Music folder to Dropbox, but I cannot figure out how to do so. I am using Dropbox API and here's my code

import dropbox
dbx = dropbox.Dropbox('*******')
dbx.users_get_current_account()

f = open('Channa Mereya.mp3', 'rb')
dbx.files_upload(bytes(f.read()), 'Channa Mereya.mp3')

but I get the error

dropbox.stone_validators.ValidationError: 'Channa Mereya.mp3' did not match pattern '(/(.|[\r\n])*)|(ns:[0-9]+(/.*)?)'

I don't know much about regex patterns. Also while reading API documentation, files_upload takes first argument as bytes, I don't why it takes bytes.

I also tried to just pass the path of mp3 file instead of opening and passing the file like

dbx.files_upload("/home/username/python projects/Channa Mereya.mp3", 'Channa Mereya.mp3')

Here Channa Mereya.mp3 is a mp3 file stored in the same directory as the script

Greg
  • 16,359
  • 2
  • 34
  • 44
Yash Lotan
  • 378
  • 1
  • 5
  • 21

1 Answers1

0

When specifying a file path to upload to in Dropbox API v2, the path should have a leading "/" to identify root. So, the second parameter to files_upload should look like '/Channa Mereya.mp3'.

The error is indicating that your path value 'Channa Mereya.mp3' doesn't match the allowed pattern, i.e., it doesn't have that leading slash.

Greg
  • 16,359
  • 2
  • 34
  • 44