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: object

HTTP POST client with header management and JSON response validation.

Wraps a persistent requests.Session and provides methods to configure headers, define a default JSON payload, and execute POST requests with automatic validation of the Solenso API response (status and message fields).

Parameters:

timeout (int) – Request timeout in seconds. Defaults to DEFAULT_TIMEOUT (10 s).

timeout

Configured request timeout.

Type:

int

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 headers: Dict[str, str]

Current HTTP headers of the session.

Returns:

Current headers dictionary.

Return type:

Dict[str, str]

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:
  • key (str) – Header name (e.g. "Authorization").

  • value (str) – Header value.

Return type:

None

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.

Parameters:

key (str) – Header name to remove.

Return type:

None

set_headers(headers)[source]

Merge a dictionary of headers into the existing headers.

Existing keys are overwritten; new keys are added.

Parameters:

headers (Dict[str, str]) – Headers to merge.

Return type:

None

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 payload is not a dictionary.

Return type:

None

post(url, payload=None)[source]

Perform a JSON POST request and return the validated data.

Sends payload (or raw_payload if None) to url, checks the HTTP status, validates the Solenso API response structure (status == "0" and message == "success"), then returns only the content of the data field.

Parameters:
Returns:

Content of the data field from the JSON response.

Return type:

dict

Raises:

Example

client = MySolensoPost()
client.set_headers(auth.get_auth_headers_solenso())
data = client.post(API_USER_ME)
print(data["user_name"])
poststr(url, payload=None)[source]
Return type:

bytes