Hi guys
Thanks for a great resource!
I'm trying to figure out what is wrong with my script. But first, login, authorization and token fetch works find. Group creation, deletion and template deletion works. However template creation does not. I'm starting to think that I'm handling the config file upload wrong somehow.
The following code returns an internal server error 500.
def AC_TemplateCreate(group_name, template_name):
params = {
"access_token": CRED_ACCESS_TOKEN,
"name": template_name,
"device_type":"ArubaSwitch",
"version":"ALL",
"model":"ALL"
}
# URL_BASE = "https://eu-apigw.central.arubanetworks.com"
# URL_GROUPS = "/configuration/v1/groups"
# URL_TEMPLATES = URL_GROUPS + "/{group}/templates"
url = URL_BASE + URL_TEMPLATES.replace('{group}', group_name)
file_dict = {"file": open(DIR_SCRIPT + DIR_INDIVIDUAL_CFG + r'\\' + template_name + '.txt', 'rb')}
headers = {'Content-type': 'multipart/form-data'}
resp = requests.post(url, params=params, files=file_dict, headers=headers)
if (resp.status_code != 200) and (resp.status_code != 201):
print('Failed to create template ' + template_name + '! The code is: {}'.format(resp.status_code))
print(resp.text)
#sys.exit()
else:
print('Created template: ' + template_name)
I realize this isnt all that self explanatory. But if you guys can see a better way of handling posting form data than what i'm doing here i'm curious to learn.
Thanks in advance
Cheers
/Kim
Thanks in advance