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: 

Re: file_properties_properties_add() - InternalServerError('', 500, '')

file_properties_properties_add() - InternalServerError('', 500, '')

ADoncel
Explorer | Level 4
Go to solution

Hello,

 

I'm using Python 3.6 and Dropbox API installed with pip under Linux 4.4.0-18362-Microsoft #476-Microsoft Fri Nov 01 16:53:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux (WSL Ubuntu).

 

I'm short it out everything to be able to add my own properties to the files but, everything fails in the last command, when I tried to execute:

```

try:

     self.dbx_api.file_properties_properties_add(p_target_file, properties_add)

except dropbox.exceptions.ApiError as err:

      sys.exit("ERROR: Add properties fail for " + p_target_file + " -- Property group alredy exist" + err)

```

 

It just crash retrieving me the next error: InternalServerError('520046d8f13fee9b6959c55e5a304c83', 500, '')

I would like to add that it takes a few seconds to raise that error, but my file is uploaded and my property_template is added to the user. Also, it should crash if I try to add the same template twice for the same user and I added it like 20 times without any problem, if I list my templates looks like this:

 

GetTemplateResult(name='media_file', description='Properties for media files (photos/videos)', fields=[PropertyFieldTemplate(name='date', description='Date when the file was upload', type=PropertyType('string', None)), PropertyFieldTemplate(name='attraction', description='Attraction where the media was done', type=PropertyType('string', None)), PropertyFieldTemplate(name='park', description='Park where the media was done', type=PropertyType('string', None)), PropertyFieldTemplate(name='uid', description='Uniq identifier for the object', type=PropertyType('string', None)), PropertyFieldTemplate(name='file_type', description='Type of file (video/photo)', type=PropertyType('string', None))])

 

GetTemplateResult(name='media_file', description='Properties for media files (photos/videos)', fields=[PropertyFieldTemplate(name='date', description='Date when the file was upload', type=PropertyType('string', None)), PropertyFieldTemplate(name='attraction', description='Attraction where the media was done', type=PropertyType('string', None)), PropertyFieldTemplate(name='park', description='Park where the media was done', type=PropertyType('string', None)), PropertyFieldTemplate(name='uid', description='Uniq identifier for the object', type=PropertyType('string', None)), PropertyFieldTemplate(name='file_type', description='Type of file (video/photo)', type=PropertyType('string', None))])

 . . . much more like this

 

what could it be the problem? Do you thing maybe is because WSL, maybe the Python version or API? Thank you in advance.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

Thanks! It looks like there's just a small issue in that code. The file_properties_properties_add method expects a list of 'PropertyGroup', so instead of:

dbx_api.file_properties_properties_add(p_target_file, property_group)

you should do:

dbx_api.file_properties_properties_add(p_target_file, [property_group])

View solution in original post

4 Replies 4

Greg-DB
Dropbox Staff
Go to solution

Thanks for writing this up! It looks like this happens when you specify the same template multiple times in the same call to file_properties_properties_add, instead of just once. The server error occurs because we don't handle this case properly on the Dropbox API. I'll ask the team to fix up that error handling.

 

To avoid this though, make sure you only specify a particualr template ID once per call to file_properties_properties_add. That is to say, when you make your AddPropertiesArg, you can add properties for multiple templates, but you should only specify one PropertyGroup in AddPropertiesArg.property_groups per template. If you have multiple fields to set for a template, you should set those multiple fields as a list in the one PropertyGroup.fields for the template. Please feel free to share the code where you build your 'properties_add' variable if you'd like more specific help with that.

 

Also, regarding "it should crash if I try to add the same template twice for the same user", the Dropbox API allows you to create multiple templates for the same user, so if you do call 'file_properties_templates_add_for_user' multiple times, even with the same parameter values, that will create multiple templates for that user. If only need one template, you should only call that once per user.

ADoncel
Explorer | Level 4
Go to solution

Hello, 

 

Thank you very much for the answer.

I didn't one PropiertyGroup with more than one field because in that case this error raises:

 

Exception has occurred: ValidationError - PropertyGroup(template_id='ptid:iMdPSELQckAAAAAAAAAAIQ', fields=[PropertyField(name='date', value='1548965874'), PropertyField(name='park', value='x'), PropertyField(name='attraction', value='y'), PropertyField(name='file_type', value='video'), PropertyField(name='uid', value='AS46561sdg99wrDSD9e6f1e')]) is not a valid list.

 

Due to this, I was passing a list of PropertyGroup, one for each field I need to write and I get the 500 error,  so I'm stuck here.

 

This is what I do to create everything in case there is something wrong here:

self.dbx_api = dropbox.Dropbox(self.token, timeout=p_timeout)

# Confirm the access token is valid:
try:
    self.dbx_api.users_get_current_account()
except dropbox.exceptions.AuthError:
    sys.exit("ERROR: Invalid access token; try re-generating an access token from the app console on the web or asking to you System Administrator")

string_t = dropbox.file_properties.PropertyType.string
date = dropbox.file_properties.PropertyFieldTemplate(
                'date', 
                'Date when the file was upload', 
                string_t)
park = dropbox.file_properties.PropertyFieldTemplate(
                'park', 
                'Park where the media was done', 
                string_t)
attraction = dropbox.file_properties.PropertyFieldTemplate(
                'attraction', 
                'Attraction where the media was done', 
                string_t)
f_type = dropbox.file_properties.PropertyFieldTemplate(
                'file_type', 
                'Type of file (video/photo)', 
                string_t)
uid = dropbox.file_properties.PropertyFieldTemplate(
                'uid', 
                'Uniq identifier for the object', 
                string_t)

template = self.dbx_api.file_properties_templates_add_for_user(
                'media_file', 
                'Properties for media files (photos/videos)', 
                [date, park, attraction, f_type, uid])

self.template_id = template.template_id

date_property       = dropbox.file_properties.PropertyField('date', p_date)
park_property       = dropbox.file_properties.PropertyField('park', p_park)
attraction_property = dropbox.file_properties.PropertyField('attraction', p_attraction)
f_type_property     = dropbox.file_properties.PropertyField('file_type', p_f_type)
uid_property        = dropbox.file_properties.PropertyField('uid', p_uid)

property_group = dropbox.file_properties.PropertyGroup(
            self.template_id, [date_property, park_property, attraction_property, f_type_property, uid_property])

try:
     self.dbx_api.file_properties_properties_add(p_target_file, property_group)
except dropbox.exceptions.ApiError as err:
     sys.exit("ERROR: Add properties fail for " + p_target_file + " -- Property group alredy exist" + err)

In this case I get the error above, and if I try what I explain you the last day:

 

property_data = dropbox.file_properties.PropertyGroup(self.template_id, [date_property])
property_park = dropbox.file_properties.PropertyGroup(self.template_id, [park_property])
property_attrac = dropbox.file_properties.PropertyGroup(self.template_id, [attraction_property])
property_type = dropbox.file_properties.PropertyGroup(self.template_id, [f_type_property])
property_uid = dropbox.file_properties.PropertyGroup(self.template_id, [uid_property])

peropety_gr_list = [property_data, property_park, property_attrac, property_type, property_uid]

try:
     self.dbx_api.file_properties_properties_add(p_target_file, peropety_gr_list)
except dropbox.exceptions.ApiError as err:
     sys.exit("ERROR: Add properties fail for " + p_target_file + " -- Property group alredy exist" + err)

I got the 500 error. Also, I'd like to say that I already delete every Template in the user to work only with one first of all, but still in the same situation.

Greg-DB
Dropbox Staff
Go to solution

Thanks! It looks like there's just a small issue in that code. The file_properties_properties_add method expects a list of 'PropertyGroup', so instead of:

dbx_api.file_properties_properties_add(p_target_file, property_group)

you should do:

dbx_api.file_properties_properties_add(p_target_file, [property_group])

ADoncel
Explorer | Level 4
Go to solution

That was the thing I was missing.

 

Thank you very much.

Need more support?