Hello Jamie
I'm doing a very simple python 3 Script to query the activate inventory.
The problem is that the server is ignoring the body json filters, although URL filters are working.
According to the doc, I wrote the code below.
Json body filter is completely ignored, and if I omit the URL filter the response is so big I get HTTP 504.
Everything is working but the body Mac device filter.
Could you give a hand?
Thank you very much
import os, sys, re, argparseimport urllib.requestimport urllibimport jsonimport tracebackline="https://activate.arubanetworks.com"string_oauth={"credential_0" : "XXXXX","credential_1": "XXXXXX"}jsonbody_url=urllib.parse.urlencode(string_oauth)jsonbody_bytes = jsonbody_url.encode("utf-8")
print('Autenticando en : ',line)req=urllib.request.Request(url=line+"/LOGIN",data=jsonbody_bytes,method='POST')#construimos y enviamos consulta httptry:f=urllib.request.urlopen(req)except urllib.error.HTTPError as e:if hasattr(e, 'code'):print('ERROR HTTP ', e.code)if hasattr(e, 'detail'):print('Reason: ', e.detail)print("autenticación failed:Closing Application")sys.exit(e.code)else:print("Authentication succeed")cookie=f.getheader('Set-Cookie')string_query={"devices" : [ "34:FC:B9:CE:12:30" , "20:4C:03:14:24:9C" ]}json_alta_guest=json.dumps(string_query)json_alta_guest_bytes=json_alta_guest.encode('utf-8')req=urllib.request.Request(line+"/api/ext/inventory.json?action=query&addDate=06-15-2017",data=json_alta_guest_bytes,headers={"Cookie" : cookie,"Content-Type": "Application/json", "charset":"UTF-8","Connection": "Keep-Alive"},method='POST')try:f=urllib.request.urlopen(req)except urllib.error.HTTPError as e:var=e.read().decode("utf-8")print("HTTP "+str(e.code)+" "+"")
else:
print(f.headers)data = json.loads(f.read().decode('utf-8'))print(data)
© Copyright 2024 Hewlett Packard Enterprise Development LPAll Rights Reserved.