Convert Python data to JSON and bytes. Args: data: Data to encode, anything json.dumps can handle. Returns: The GLib Bytes or None if something failed.
(self, data: Any)
| 26 | """ Max number of tries """ |
| 27 | |
| 28 | def encode_data(self, data: Any) -> GLib.Bytes | None: |
| 29 | """ |
| 30 | Convert Python data to JSON and bytes. |
| 31 | |
| 32 | Args: |
| 33 | data: Data to encode, anything json.dumps can handle. |
| 34 | |
| 35 | Returns: |
| 36 | The GLib Bytes or None if something failed. |
| 37 | """ |
| 38 | data_glib_bytes = None |
| 39 | try: |
| 40 | data_bytes = json.dumps(data).encode("utf-8") |
| 41 | data_glib_bytes = GLib.Bytes.new(data_bytes) |
| 42 | except Exception as exc: |
| 43 | logging.warning(exc) |
| 44 | return data_glib_bytes |
| 45 | |
| 46 | def create_message( |
| 47 | self, method: str, url: str, data: Any = {}, headers: dict = {}, form: bool = False |