HTTP Error 201 on successful POST API

I have written some GET API’s that work ok using the python library ‘urllib2’.
I’ve just written a POST API, and it is returning HTTP Status 201: Created.
After doing some reading, it seems any HTTP 200 status means the request was successful. So why am i getting an error thrown in Ignition?
As far as i can tell, the request was successful. I created a new item on the server end as expected.

Should I write some “try: except” code to ignore it? I don’t really want to do that without understanding why it is making an error.

Sorry I’m not hugely familiar with the HTTP web space.


Because urllib2 is stupid. All 2xx responses are success codes, but they are not normally returned by simple web servers.

You might try using the system.net HTTP functions or Java’s HTTPUrlConnection directly.

Hmmm… right. I’ve managed to find some interesting material online about urllib2’s failures to handle 20X success codes. I guess I might have to just handle it manually.

Edit: I managed to get my POST api working by using the system.net.httpPost() function, with no error thrown on HTTP status 201!! :prayer:

Although it took a bit of fiddling with the parameters to get it to work.
Not sure why this code produced a “Bad Request”: response=system.net.httpPost(requestUrl, data_dict, headerValues=urlHeader)
Yet switching ‘postParams’ for ‘postData’ and doing this succeeded: data=system.util.jsonEncode(data_dict) response=system.net.httpPost(url=requestUrl, contentType="application/json", postData=data, headerValues=urlHeader)
Where ‘data_dict’ is a pyDict.