Reputation: 29
I am trying to post test_data output from below python script (abc.py) to telegraf over http_listener_v2.
abc.py
------
import requests
url = "https://testazure.local/telegraf"
test_data = {'key1': 'value1'}
op = requests.post(url, data = test_data)
print(op.test_data)
Here is the snippets from my telegraf.conf file for inputs .
telegraf.conf
-----------------
[[inputs.http_listener_v2]]
# ## Address and port to host HTTP listener on
# methods = ["POST", "PUT"]
data_format = "json"
Not sure , if i am passing all the requsite details to the input plugin .
Getting connection error in an attempt to execute my python script . Any advise /help would be highly appreciated .
Traceback (most recent call last):
File "abc.py", line 6, in <module>
x = requests.post(url, data = test_data)
File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 119, in post
return request('post', url, data=data, json=json, **kwargs)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host'testazure.local', port=443):
Max retries exceeded with url: /telegraf (Caused by
NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f9eb8c72438>:
Failed to establish a new connection: [Errno 111] Connection refused',))
Upvotes: 2
Views: 1387
Reputation: 33
I think your url needs http and not https. I have this exact setup and I am looking for an answer as well.
Actually seeing your question, I was able to solve my problem. I had the following code... notice the post method arguments... json
host = "rpi4-2GB"
port = 8080
path = "/telegraf"
weather_dict = data
url_str = "http://{}:{}{}".format(host, port, path)
http_res = requests.post(url=url_str, json=dumps(weather_dict))
>>> http_res.status_code
400
after reading your question here, I changed my kwarg to data
url_str = "http://{}:{}{}".format(host, port, path)
http_res = requests.post(url=url_str, data=dumps(weather_dict))
>>> http_res.status_code
204
204 is the proper value to get back from my experience with telegraph's http_listener_v2
plugin.
Upvotes: 1