mysolenso.post - HTTP Client
Generic HTTP POST module for MySolenso requests.
Provides the MySolensoPost class, a lightweight and configurable
HTTP client that wraps a requests session with header management,
JSON payload handling, and response validation.
This module is used internally by the services
(mysolenso.services.me and mysolenso.services.station)
to avoid code duplication.
Example
Typical usage inside a service:
from mysolenso.post import MySolensoPost
client = MySolensoPost(timeout=15)
client.set_headers({"Cookie": "solenso_token=..."})
data = client.post("https://monitor.solenso.net/api/...")
- class mysolenso.post.MySolensoPost(timeout=10)[source]
Bases:
objectHTTP POST client with header management and JSON response validation.
Wraps a persistent
requests.Sessionand provides methods to configure headers, define a default JSON payload, and execute POST requests with automatic validation of the Solenso API response (statusandmessagefields).- Parameters:
timeout (
int) – Request timeout in seconds. Defaults toDEFAULT_TIMEOUT(10 s).
Example
client = MySolensoPost() client.set_header("Cookie", "solenso_token=tok123") result = client.post("https://monitor.solenso.net/api/endpoint") print(result) # dict from the data{} field
- property raw_payload: Dict[str, Any]
Default JSON payload used when
post()receives no payload.- Returns:
Current default payload.
- Return type:
Dict[str, Any]
- set_header(key, value)[source]
Add or replace a single HTTP header.
- Parameters:
- Return type:
Example
client.set_header("X-Custom", "value")
- remove_header(key)[source]
Remove an HTTP header if it exists.
No exception is raised if the key is absent.
- set_headers(headers)[source]
Merge a dictionary of headers into the existing headers.
Existing keys are overwritten; new keys are added.
Example
client.set_headers(auth.get_auth_headers_solenso())
- set_raw_payload(payload)[source]
Set the default JSON payload sent by
post().- Parameters:
payload (
Dict[str,Any]) – JSON body to store. Must be a dictionary.- Raises:
MySolensoException – If
payloadis not a dictionary.- Return type:
- post(url, payload=None)[source]
Perform a JSON POST request and return the validated data.
Sends
payload(orraw_payloadifNone) tourl, checks the HTTP status, validates the Solenso API response structure (status == "0"andmessage == "success"), then returns only the content of thedatafield.- Parameters:
- Returns:
Content of the
datafield from the JSON response.- Return type:
- Raises:
MySolensoAuthenticationException – If the response
statusfield is not"0"ormessageis not"success".MySolensoException – On timeout, HTTP error, or invalid JSON response.
Example
client = MySolensoPost() client.set_headers(auth.get_auth_headers_solenso()) data = client.post(API_USER_ME) print(data["user_name"])