简体   繁体   中英

Azure: Creating public ip address with Python

I'm trying to create a public ip address in Azure with the Python SDK and I can't figure out why am I getting an error. Here's my code:

netclient.public_ip_addresses.create_or_update('testgrp','testsdknic',{'location':'uksouth','sku':'standard','public_ip_allocation_method':'dynamic','public_ip_address_version':'ipv4'})

And this is the error I get:

SerializationError: Unable to build a model: Unable to deserialize to object: type, AttributeError: 'str' object has no attribute 'get', DeserializationError: Unable to deserialize to object: type, AttributeError: 'str' object has no attribute 'get'

I have tried several things but while I'm succeeding in creating a network interface, I can't create the public IP. Could anyone provide me with some guidance here please? Many thanks in advance.

For this issue, it caused by the property sku of the public IP address, it's the string, but a PublicIPAddressSku . So the code you need to change into this:

netclient.public_ip_addresses.create_or_update('testgrp','testsdknic',{'location':'uksouth',
'sku':{'name': 'standard'},'public_ip_allocation_method':'static','public_ip_address_version':'ipv4'})

And watch out, when you use the standard for the public IP address, then it should be in the static allocation method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM