cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I make apiError as a string

chunchk
Explorer | Level 4

Hello, I am new in here

I try to develop a script that can auto email a Dropbox link to someone

I am using .sharing_create_shared_link_with_settings to determine does the file had been shared or not

However, now I encounter a new python exception which is "not_found",

my situation is, now I have 2 python exceptions, "not_found" and "shared_link_already_exists"

my question is, how do I let python know that the exception is "not_found" or "shared_link_already_exists" , so I can code some actions depends on the different exception

2 Replies 2

Re: How do I make apiError as a string

Dropboxer
Dropboxer

Here's an example of how you can tell apart different errors:

 

import dropbox
from dropbox.exceptions import ApiError

dbx = dropbox.Dropbox("<ACCESS_TOKEN>")

try:
    print(dbx.sharing_create_shared_link_with_settings("/test222.txt"))
except ApiError as err:
    if err.error.is_shared_link_already_exists():
        print("Link already exists.")
    if err.error.is_path() and err.error.get_path().is_not_found():
        print("File not found.")
    elif err.error.is_settings_error():
        print(err.error.get_settings_error())
    else:
        print(err)

Re: How do I make apiError as a string

chunchk
Explorer | Level 4

Oh~I see~!

Thank you for your help

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?