koalalorenzo/python-digitalocean

Volumes return empty list on droplet

al-an-f opened this issue · 4 comments

Hello!
I noticed a certain feature of the behavior of your python module for working with the Digital Ocean API.
The thing is, when I execute the following code:

import digitalocean as d_o
manager = d_o.Manager (token = do_read_token)
droplets = manager.get_all_droplets ()
for droplet in droplets:
    print (droplet.id, droplet.name, droplet.volumes)

The value droplet.volumes for each droplet in this case is an empty list ([])

However, if I make a request directly to the api DO by executing the following code:

import requests as req
import json
api_url_base = 'https://api.digitalocean.com/v2/'
headers = {'Content-Type': 'application / json', 'Authorization': 'Bearer {0}'. format (do_read_token)}
api_url = '{0} droplets'.format (api_url_base)
response = req.get (api_url, headers = headers)
if response.status_code == 200:
    dict_droplets = json.loads (response.content.decode ('utf-8'))
    for droplet in dict_droplets.get ('droplets'):
print (droplet.get ('id'), droplet.get ('name'), droplet.get ('volume_ids'))
response.close ()

For each droplet.get ('volume_ids') in this case, I get a non-empty list with id volomes for each droplets.

Is this normal behavior of the API or can it be fixed somehow?

Both scripts are executed for one account, in each droplet of which there are connected volumes

The python-digitalocean module version is 1.14.0
Python version - 3.6.7

Indeed issue is reproducible after removing spaces from you provided code samples, with the same lib version and python 3.5

#283 checkout this PR

@koalalorenzo could you close the issue?

I thought it was automatic like on GitLab.com