koalalorenzo/python-digitalocean

Resources value missing error when adding tags to droplets via tag object

Closed this issue · 7 comments

After I fixed #237 locally I ran into:

Traceback (most recent call last):
  File "streambot.py", line 145, in <module>
    get_default_tag_name(), get_default_snapshot_name(), get_default_firewall_name())
  File "streambot.py", line 119, in create_or_get_single_droplet_from_snapshot
    tag.add_droplets([droplet.id])
  File "/home/thatra/Code/streambot/venv/lib/python3.5/site-packages/digitalocean/Tag.py", line 129, in add_droplets
    return self.__add_resources(resources)
  File "/home/thatra/Code/streambot/venv/lib/python3.5/site-packages/digitalocean/Tag.py", line 74, in __add_resources
    return self.__get_resources(resources, method='POST')
  File "/home/thatra/Code/streambot/venv/lib/python3.5/site-packages/digitalocean/Tag.py", line 62, in __get_resources
    type=method,
  File "/home/thatra/Code/streambot/venv/lib/python3.5/site-packages/digitalocean/baseapi.py", line 184, in get_data
    raise DataReadError(msg)
digitalocean.baseapi.DataReadError: param is missing or the value is empty: resources

The resources dict appears fine at the request dispatch point, but the request returns 400.

Adding tags works fine when done via droplet object create method.

Same issue here!

Could you create a PR with fixes for this? That would be cool

I will look deeper into this once I finish my bot

ats3v commented

I'm getting the same error. According to DigitalOcean I am sending a malformed json, which is absurd. They must have changed something in their API format. Sadly, the API reference pages don't show any changes.
Today the error changed to:

digitalocean.baseapi.DataReadError: your request is malformed, please check your syntax: json: cannot unmarshal number into Go struct field Resource.resource_id of type string

Will experiment with sending the ids as numbers instead of string.

Probably somebody from Digital Ocean should have a look at this.

ats3v commented

OK, so we are sending droplet IDs as numbers, whereas the DigitalOcean API expects strings. Here are the reference pages: https://developers.digitalocean.com/documentation/v2/#tag-a-resource

After passing a list of IDs in the form of strings to Tag::add_droplets, the request was successful.

The fix must be in __extract_resources_from_droplets - we should always pass IDs as strings.

DigitalOcean must have started to verify the input data more strictly. I hope this is the only place where we fail their validation.

Finally got back around to this. As linked by goodcode __extract_resources_from_droplets is used for calls to add tags and remove tags which both require strings. I tested locally with py2/3 and all variations of accepted objects. The validation seems to be passing.