Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
I have a python script that's calling a ThingWorx Service. I'm calling a different service elsewhere in the script and it's working, but I'm not sure why this one isn't. The only difference is that this service has an InfoTable input.
Here's the relevant code.
propNames = {
"dataShape": {
"fieldDefinitions": {
"name": {
"name": "name",
"baseType": "STRING"
},
"description": {
"name": "description",
"baseType": "STRING"
}
}
},
"rows": [{"name": "Stat_DisplaySpeed1"}]
}
params = {
"maxItems": 500,
"propertyNames": propNames,
"startDate": startDate.replace(tzinfo=timezone.utc).isoformat(),
"endDate": endDate.replace(tzinfo=timezone.utc).isoformat(),
"query": ""
}
headers = {
"appKey": PROD_KEY,
"Accept": "application/json",
"Content-Type": "application/json"
}
r = requests.post(url, params=params, headers=headers)
(startDate and endDate are defined elsewhere in the code)
This results in a status code of 406 with the body "Unable To Parse JSON Request"
Am I somehow forming "propertyNames" incorrectly? I'm confused about what's going on here.
Solved! Go to Solution.
I get a different error "accessing data provider" when I send without any data.
But going the route of QueryNumberPropertyHistory is working.
Could you please share your TWX service code?
This is calling the built in QueryNamedPropertyHistory service.
I have not done this from Python. So, I could be wrong. Probably you need to enclose propNames value in double quotes(beginning and end) and escape all other ones.
"{\"dataShape\":{\"fieldDefinitions\":{\"name\":{\"name\..........."
So you're saying propNames actually needs to be converted to a JSON string and passed along? Tried that, didn't work.
Execute QueryNamedPropertyHistory from composer and use Chrome Developer tools to get the request payload being used for the execution. You could then modify this to generate your call.
I have copy-pasted from Chrome's inspector and I still get the error.
Hello @mdszy ,
I would troubleshoot it as follows:
1. Try to call it without any parameters at all (empty JSON)
2. If it works, start adding parameters one by one in this order: maxItems, startDate / endDate (by the way, I think you might need them in milliseconds-since-epoch here, not ISO strings), and finally propertyNames
3. Alternatively, since you're querying only one property anyway, I would recommend using QueryStringPropertyHistory (or its analogue for Number, etc.), which doesn't require INFOTABLE parameter, but only a String
/ Constantine
I get a different error "accessing data provider" when I send without any data.
But going the route of QueryNumberPropertyHistory is working.