Make a POST request to the API. Args: path: The API path. data: The request body. params: Optional query parameters. Returns: The API response. Raises: AgentRPCError: If the request fails for any reason.
(
self, path: str, data: Dict[str, Any], params: Optional[Dict[str, Any]] = None
)
| 190 | raise AgentRPCError(f"Unexpected error: {str(e)}") |
| 191 | |
| 192 | def post( |
| 193 | self, path: str, data: Dict[str, Any], params: Optional[Dict[str, Any]] = None |
| 194 | ) -> Any: |
| 195 | """Make a POST request to the API. |
| 196 | |
| 197 | Args: |
| 198 | path: The API path. |
| 199 | data: The request body. |
| 200 | params: Optional query parameters. |
| 201 | |
| 202 | Returns: |
| 203 | The API response. |
| 204 | |
| 205 | Raises: |
| 206 | AgentRPCError: If the request fails for any reason. |
| 207 | """ |
| 208 | url = f"{self.endpoint}{path}" |
| 209 | |
| 210 | try: |
| 211 | response = requests.post( |
| 212 | url, json=data, params=params, headers=self.headers |
| 213 | ) |
| 214 | response.raise_for_status() |
| 215 | return response.json() |
| 216 | except requests.HTTPError as e: |
| 217 | raise AgentRPCError( |
| 218 | f"HTTP error: {e.response.status_code} - {e.response.text}", |
| 219 | status_code=e.response.status_code, |
| 220 | response=e.response.text, |
| 221 | ) |
| 222 | except requests.RequestException as e: |
| 223 | raise AgentRPCError(f"Request error: {str(e)}") |
| 224 | except Exception as e: |
| 225 | raise AgentRPCError(f"Unexpected error: {str(e)}") |
no test coverage detected