1 |
7a278c5c
|
silhavyj
|
import json
|
2 |
|
|
import requests
|
3 |
|
|
import logging
|
4 |
|
|
|
5 |
|
|
from requests import HTTPError, ConnectionError
|
6 |
|
|
|
7 |
|
|
from config_manager import server_url, server_port, server_endpoint
|
8 |
|
|
|
9 |
d1528a79
|
silhavyj
|
|
10 |
7a278c5c
|
silhavyj
|
_uri = server_url + ":" + server_port + server_endpoint
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
def send_data(payload: dict):
|
14 |
|
|
try:
|
15 |
|
|
logging.info(f"sending payload = {payload} to {_uri}")
|
16 |
|
|
response = requests.post(url=_uri, data=json.dumps(payload))
|
17 |
|
|
logging.info(f"response text: {response.text}")
|
18 |
|
|
except ConnectionError:
|
19 |
|
|
logging.warning(f"sending payload = {payload} to {_uri} failed")
|
20 |
|
|
except HTTPError as error:
|
21 |
|
|
logging.error(f"HTTP Error ({_uri}) payload = {payload}, {error}")
|