We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
ADoncel
6 years agoExplorer | Level 4
file_properties_properties_add() - InternalServerError('', 500, '')
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...
- 6 years ago
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])
Greg-DB
Dropbox Community Moderator
6 years agoThanks 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
6 years agoExplorer | Level 4
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-DB6 years ago
Dropbox Community Moderator
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])
- ADoncel6 years agoExplorer | Level 4
That was the thing I was missing.
Thank you very much.
About 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!