Can't append with Error on Python Code

Hi,

how to solve this error. ps help. Tks.

line 68, in <module>
    volume_id.Apppend(result['volume']['id'])
AttributeError: 'list' object has no attribute 'Apppend'


i need more than one system-volumes but created on volume only in the cloud platform. Ps advice. Tks


start_number = 1
number_of_volumes = 10
volume_id = []

for i in range(number_of_volumes):
    vol_no = start_number + i
    create_volume_url = "https://domain.com/v2/cd088007d3b84e7fa894478e6fe667c4/volumes"
    body = {"volume":
        {
            "size": 60,
            "availability_zone": "az0.dc0",
            "volume_type": "ssd",
            "name": "vol" + str(vol_no),
            "multiattach": False,
            "imageRef": "c54d05fa-5ad8-425e-be56-e60ede395230"
        }
    }
    headers = {
        'content-type': "application/json",
        'X-Auth-Token': token
    }

    result = requests.post(create_volume_url, json=body, headers=headers, verify=False)
    volume_id.apppend(result['volume']['id'])
    print(result.json())
Lucky ThamFreelancerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Python is case-sensitive, that error message mentions 'Append'.

Are you sure you haven't used 'Append' instead of 'append' somewhere in the code?
Lucky ThamFreelancerAuthor Commented:
yes. is the same error no matter i tried "append" or "Append" is the same error.
NorieAnalyst Assistant Commented:
Is this definitely the line of code causing the error?
    volume_id.apppend(result['volume']['id'])

Open in new window

Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Lucky ThamFreelancerAuthor Commented:
i am not quite sure just based on the error message. Can you shine some light? Tks.
NorieAnalyst Assistant Commented:
Does this work?
    volume_id += [result['volume']['id']]

Open in new window

Lucky ThamFreelancerAuthor Commented:
no. tks

line 69, in <module>
    volume_id += [result['volume']['id']]
TypeError: 'Response' object is not subscriptable
NorieAnalyst Assistant Commented:
How about without the outside []?
 volume_id +=  result['volume']['id']

Open in new window

Lucky ThamFreelancerAuthor Commented:
still the same. tks

line 70, in <module>
    volume_id += result['volume']['id']
TypeError: 'Response' object is not subscriptable
NorieAnalyst Assistant Commented:
What happens if you save and close the file, without the changes I suggested, and then try it again?
Lucky ThamFreelancerAuthor Commented:
save all the files. restarted pycharm but still the same error. tks
Lucky ThamFreelancerAuthor Commented:
could it be require times to create the system volumes from the cloud. But it shouldn't be like this. When use POSTMAN to create one system volume and the response is 1550 ms and check the system volume still creating on the cloud platform.

Could it be this is the reason?

How to add a delay to the python code?

Tks.
NorieAnalyst Assistant Commented:
If you want to add a delay you could try using sleep, not sure if it'll help though.
from time import sleep

# other code

# wait for a second
sleep(1)

# continue

Open in new window

Lucky ThamFreelancerAuthor Commented:
Thanks. Still can't
nociSoftware EngineerCommented:
the error message indicated apppend (3 p's)  is used not append (2 p's) which should be available in a list
NorieAnalyst Assistant Commented:
Doh, can't believe I missed that.
Lucky ThamFreelancerAuthor Commented:
is this okay. Tks.

2.jpg
Lucky ThamFreelancerAuthor Commented:
sorry for my typo error and copied over without checking.
Lucky ThamFreelancerAuthor Commented:
# Store the urls we want to use
url = "https://ip/silvan/apigateway/v1.0/"
get_apis = "apis_include_throttles"

get_token_url = "https://iam-apigateway-proxy.domain/v3/auth/tokens"

body = {
    "auth": {
        "identity": {
            "methods": [
                "password"
            ],
            "password": {
                "user": {
                    "domain": {
                        "name": "STIC"
                    },
                    "name": "admin",
                    "password": "P@ssw0rd"
                }
            }
        },
        "scope": {
            "project": {
                "id": "cd088007d3b84e7fa894478e6fe667c4",
                "domain": {
                    "name": "SITC"
                }
            }
        }
    }
}

results = requests.post(get_token_url, json=body, verify=False)

token = results.headers['X-Subject-Token']

#print(results.headers)

start_number = 2
number_of_volumes = 2
volume_id = []

for i in range(number_of_volumes):
    vol_no = start_number + i
    create_volume_url = "https://evs.domain.com/v2/cd088007d3b84e7fa894478e6fe667c4/volumes"
    body = {"volume":
        {
            "size": 60,
            "availability_zone": "az0.dc0",
            "volume_type": "ssd",
            "name": "SITC-v" + str(vol_no),
            "multiattach": False,
            "imageRef": "c54d05fa-5ad8-425e-be56-e60ede395230"
        }
    }
    headers = {
        'content-type': "application/json",
        'X-Auth-Token': token
    }

    result = requests.post(create_volume_url, json=body, headers=headers, verify=False)
    volume_id.append(result['volume']['id'])
    print(result.json())


print(volume_id)
NorieAnalyst Assistant Commented:
How about this?

result = requests.post(create_volume_url, json=body, headers=headers, verify=False)

response_data = result.json()

volume_id.append(response_data['volume']['id'])

Open in new window

Lucky ThamFreelancerAuthor Commented:
just in case the code may have error so copy whole thing.  I think should be oaky just that the append reporting issue as i can still create one VM on the cloud platform except I can't create more than 2 VM.

Thanks for helping!
Lucky ThamFreelancerAuthor Commented:
Thanks. Norie. You are great.

Thanks everyone helping.
Lucky ThamFreelancerAuthor Commented:
May I know what is wrong to the logic? Tks.
Lucky ThamFreelancerAuthor Commented:
can ask is there a better way to delete all the volume id being created from the above code without manually copy one by one to paste it below to delete it. Tks  

# POST to the API
results = requests.post(get_token_url, json=body, verify=False)
token = results.headers['X-Subject-Token']

#Deletion

volume_id = [
    '2336ed71-5d8f-410a-9dc7-01b452ab6ad9',
    '3cf77fd9-8ef8-4c4f-82ec-b249eb2e8df0',
    '65115cf6-743c-4225-83c7-451095e58ff0',
    'f09d0fd8-ae1c-45f7-94b0-d5436a80748e',
    'eb3d9e0a-1e10-4acb-bc55-6ce83344c625',
    '32d2106b-d8cd-4e4b-91a3-e33ade200ac3'
]

delete_url = "https://evs.domain.com/v2/cd088007d3b84e7fa894478e6fe667c4/volumes/"
headers = {
    'content-type': "application/json",
    'X-Auth-Token': token
}
for id in volume_id:
    r = requests.delete(delete_url + id, headers=headers, verify=False)
    print(r.text)
Lucky ThamFreelancerAuthor Commented:
I hope someone can help for the one-to-one live support (pay as a service) from Expert Exchange.

I need some help for coding just to perform this simple item as follow.

1. create 1000 VMs for script 1
2. delete all the system volumes for script 2
3. delete all the VM for script 3

This can help me to speed up the infra and API call testing on the cloud platform by this week and use this script as a template for future deployment.

Ps advice accordingly if there is any better suggestion from the above coding.

Just to take note that I'm not a developer or good programmer and i am a system administrator only and still learning to cope with this new job.

Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Cloud Computing

From novice to tech pro — start learning today.