Projekt

Obecné

Profil

Stáhnout (654 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1 7d0a826e 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
_uri = server_url + ":" + server_port + server_endpoint
10
11
12
def send_data(payload: dict):
13
    try:
14
        logging.info(f"sending payload = {payload} to {_uri}")
15
        response = requests.post(url=_uri, data=json.dumps(payload))
16
        logging.info(f"response text: {response.text}")
17
    except ConnectionError:
18
        logging.warning(f"sending payload = {payload} to {_uri} failed")
19
    except HTTPError as error:
20
        logging.error(f"HTTP Error ({_uri}) payload = {payload}, {error}")