Forum Discussion

Thang2000's avatar
Thang2000
Explorer | Level 4
2 years ago

why there is no option for write mode for move/copy files

I notice there is an option to use writemode

 

 

 

mode=dropbox.files.WriteMode.overwrite

 

 

 

when using uploading API ( dbx.files_upload() ), but there is no option for copying/moving file api. Can we add that? I'm using Python SDK: 

 

 

 

dbx.files_move_v2()
dbx.files_copy_v2()

 

 

 

 and have been writing many boilerplates to handle file conflicts.

Also, what is the proper way to handle this, right now I'm doing:

 

 

 

try:
    dbx.files_copy_v2(from_path=entry.path_display, to_path=path_to_autopdf_folder)
except WriteConflictError as e:

 

 

 


but getting "catching classes that do not inherit from baseexception is not allowed python". 

Appreciate the help.

  • Здравко's avatar
    Здравко
    Legendary | Level 20
    Thang2000 wrote:

    ...
    Also, what is the proper way to handle this, right now I'm doing:

     

    try:
        dbx.files_copy_v2(from_path=entry.path_display, to_path=path_to_autopdf_folder)
    except WriteConflictError as e:

     

    but getting "catching classes that do not inherit from baseexception is not allowed python". 
    ...

    Hi Thang2000,

    In most programing languages not all types can be thrown (and catched, of course), but only a subset (so called throwable types). As you saw already, in Python that subset is form of types inherited from the mentioned class. That's it. Here make a note that you are trying to catch WriteConflictError class' object; a class that is regular, non throwable (i.e. not exception) class. All errors that comes from API use ApiError class as a carrier. There you can inspect what's in error field to see what's the actual error (including its type). You may put the carrier class in all similar except statements where the target is Dropbox API and once catch the error actual error type can be found out. 😉

    Hope this clarifies matter to some extent.