JSON formatting error confusion

Hi all!

I'm currently working on making API calls to an AXIS camera using ignition scripting and have been trying to understand the following error for a little bit now and cannot make heads nor tails of it.

The script(s) are:

import httplib
import urllib2
import urllib
import json

headers = {
"Content-type": "application/json", 
"Accept": "application/json,text,raw", 
"apiVersion": "1.0",
"method": "getApiList",
"params": {
    "id": "api-discovery"
    }
}
url = "http://***server***/axis-cgi/streamprofile.cgi"
password = urllib2.HTTPPasswordMgrWithDefaultRealm()
password.add_password(None, url, "***username***", "***password***")
handler = urllib2.HTTPDigestAuthHandler(password)
opener = urllib2.build_opener(handler)
response = opener.open(url, headers)


data = json.load(response)   
data = json.dumps(data)
print data

or 

data = urllib.urlencode({'q': 'Status'})
h = httplib.HTTPConnection('***server***')
headers = {
"Content-type": "application/json", 
"Accept": "application/json,text,raw", 
"apiVersion": "1.0",
"method": "getSupportedVersions",
"params": {
    "id": "api-discovery"
    }
}
u = urllib2.urlopen('http://***server***/axis-cgi/apidiscovery.cgi?', data)
h.request('POST', '/axis-cgi/apidiscovery.cgi?', data, headers)
r = h.getresponse()
print r.read()

The error is (depending if I call user or general system):

{"error": {"code": 2001, "message": "There was an 2001 error"}}

or

{"apiVersion": "1.1", "error": {"code": 4000, "message": "JSON syntax error on line 1: '[' or '{' expected near 'q'"}}

which is:

or

You'll notice that both of these errors are JSON formatting but I can't seem to fix this issue with attempting to correct the formatting or adding things to the Header call. Whats stranger is the JSON is directly off the AXIS page with minor changes to values of the key/value pairs.

If anyone has some insight into what I'm doing wrong that would be greatly appreciated as I'm fairly new to working with API's of this sort.

Thank you,

Cam

P.S - Any recommendations on how to work with these in a more comprehensive and streamline manner would also be greatly appreciated

What do the print statements in your code reveal?

Try with ignition's built-ins:

see if it makes a difference.

2 Likes

I think we ended up figuring this out here: Strange return on an AXIS camera API call - #17 by Cameron_Nickle

1 Like