Hi Everyone,
Here I am 3 hours later for something I thought would be easy but hitting a brick wall.
Any help would be awesome
Prespective (MakerEdition) 8.1.14
I would like to get a json file from a server in my LAN. When I try to get the file using the httpClient() it succeeds (200) but I get an error when reading the json.
The response is encoded using gzip. I know this as using the curl command from command line requires the āācompressedā flag otherwise I get gibberish. Further if I look at the response headers I can see:
{u'cache-control': [max-age=0, no-cache, no-store, must-revalidate], u'connection': [close],
uācontent-encodingā: [gzip]
, u'content-length': [188], u'content-type': [application/json], u'date': [Mon, 18 Apr 2022 13:29:21 GMT], u'expires': [Fri, 31 Dec 1999 01:00:00 GMT], u'pragma': [no-cache], u'server': [Mono-HTTPAPI/1.0], u'vary': [*]}
I been through the answer MalformedJsonException: Use JsonReader.setLenient(true) however my case appears to actually be using gzip encoding.
Using that code as an example:
client = system.net.httpClient()
url = "http://<INTERNAL_IP>:8082/VirtualRadar/AircraftList.json"
headers = {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate"
}
res = client.get(url, headers=headers)
print res
print res.getHeaders()
print res.getJson('gzip')
I get the output:
<Response@1189296431 'http://<INTERNAL_IP>:8082/VirtualRadar/AircraftList.json' [200]>
{u'cache-control': [max-age=0, no-cache, no-store, must-revalidate], u'connection': [close], u'content-encoding': [gzip], u'content-length': [188], u'content-type': [application/json], u'date': [Mon, 18 Apr 2022 13:45:48 GMT], u'expires': [Fri, 31 Dec 1999 01:00:00 GMT], u'pragma': [no-cache], u'server': [Mono-HTTPAPI/1.0], u'vary': [*]}
Traceback (most recent call last):
File "<input>", line 15, in <module>
ValueError: Unable to parse response body as JSON: com.inductiveautomation.ignition.common.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 33 path $
As per the documentation Response Methods and Attributes I have tried setting the ā.getJson([encoding])ā to the following but I get the same error:
print res.getJson([gzip])
I am not sure if its to do with my headers or if the response needs decoding or probably both. Any ideas?
Thanks in advance!
EDIT
Sorry, tired and late at night; Last edit.
I am doing all this from the script console if that makes any difference.
The response when using curl:
The command:
curl http://<INTERNAL_IP>:8082/VirtualRadar/AircraftList.json --compressed -s | jq
The output:
{
"src": 1,
"feeds": [
{
"id": 1,
"name": "Receiver localhost",
"polarPlot": true
}
],
"srcFeed": 1,
"showSil": false,
"showFlg": false,
"showPic": false,
"flgH": 20,
"flgW": 85,
"acList": [],
"totalAc": 0,
"lastDv": "-1",
"shtTrlSec": 30,
"stm": 1650291163748
}