How to use HTM Engine python webapp.py

Dear all,

I am trying to use the webapp.py but I am facing issues when I want to POST data.

I was able to create a model with this command: curl http://localhost:8080/cpu -X PUT -d ‘{“min”:0, “max”:100}’ -i

But when I send a POST request like this it fails (500: internal server error): curl http://localhost:8080/cpu -X POST -d 0.35 1470301465

Anyone knows how to send POST requests to the webapp?

Thank you,
Best regards,
José Santos

What is the error in the server logs? I think it’s because you’re not sending data in the right format. From your curl command, you need to put quotes around the string data you’re sending. Also, it might need to be JSON? I can’t remember.

Hi rhyolight,

I solved the issue by sending it as on the example of the skeleton engine.

On my script, I just do:

echo $values | $curl where:

$values = 0.346 14789232
$curl = “curl http://192.168.102.139:8080/cpu -X POST -d @-”

But I would like to know exactly how can I send the values in JSON format.

Best regards,
José Santos

Here is the code I used in the HTM Engine Traffic Tutorial. It is a JavaScript HTTP client for the HTM Engine. Here is the code that POSTs data to the engine:

Look through that file for other examples of constructing HTTP requests for HTM Engine.

Ok. Thank you for the help.

htmengine doesn’t natively have an interface to receive data in json format – json is not suited for streaming data. Instead, it implements a graphite-inspired TCP interface for accepting metric data – see http://graphite.readthedocs.io/en/latest/feeding-carbon.html for more information.

htmengine alone also does not have a web server. skeleton-htmengine-app does, but is only a minimal viable example of building an app using htmengine. webapp.py in skeleton-htmengine-app does implement a HTTP interface to receive metric data via POST, and can be modified to accept json starting around https://github.com/htm-community/skeleton-htmengine-app/blob/master/webapp.py#L81

Get Outlook for Androidhttps://aka.ms/ghei36

1 Like

I should also add that in your original curl command, if you surround the metric value and timestamp with quotes, e.g. -d “0.35 1470301465”, it should work. It’s failing because curl is interpreting the timestamp as a separate argument.

Get Outlook for Androidhttps://aka.ms/ghei36

Thank you @Austin_Marshall it worked.

Best regards,
José Santos