Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

richard338's avatar
richard338
New member | Level 2
4 years ago
Solved

[Errno 13] Permission Denied; Download Convert to String from Bytes; Upload Bytes Not String

#Solved!

 

#Python SDK (python package) for Dropbox

#Problem

dbx.files_download_to_file(download_path="/downloads", path="/fileToDownload.txt")

#returns [Errno 13] Permission Denied

 

#Solution

#Omit "/" before directory path name

#download_path="downloads"

dbx.files_download_to_file(download_path="downloads", path="/fileToDownload.txt")

#end Solution section

 

#Download - Convert String to Bytes (search label references:  convert text to bytes; str() to b''; string to b''; str() to b""; string to b"")

#Also; download returns bytes variable to save to file; however, you can decode it, to save the text as a string (python str() variable type), as follows:

metadata, variable_result = dbx.files_download(path='/fileToDownload.txt')

#bytes are returned as variable_result.content

#change them to a string, as follows:

variable_bytes = variable_result.content

variable_string = variable_bytes.decode("utf-8")

f = open("saveTextHere.txt", "x")

f.write(variable_string)

f.close()

 

#Upload - Convert Bytes to String (search label references:  convert text to bytes; str() to bytes; str() to b''; str() to b""; string to b''; string to b"")

t = str("My text to save to upload file. Upload this text to user's Dropbox.com.")

b = t.encode('ascii')

f = '/newFileAtDropbox.txt'

dbx.files_upload(b, f)

#view your uploaded file; file location - Dropbox.com, folder:  Dropbox/Apps/[appFolderName]

1 Reply

Replies have been turned off for this discussion

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!