cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I make apiError as a string

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

Greg-DB
Dropbox Staff

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)

chunchk
Explorer | Level 4

Oh~I see~!

Thank you for your help

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    chunchk Explorer | Level 4
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?