TomcatManagerResponse

class tomcatmanager.models.TomcatManagerResponse(response: Response = None)

Returned as the response for TomcatManager commands.

After running a command, it’s a good idea to check and make sure that the command completed succesfully before relying on the results:

>>> import tomcatmanager as tm
>>> tomcat = getfixture("tomcat")
>>> try:
...     r = tomcat.server_info()
...     r.raise_for_status()
...     if r.ok:
...         print(f"Operating System: {r.server_info.os_name}")
...     else:
...         print(f"Error: {r.status_message}")
... except Exception as err:
...     # handle exception
...     pass
Operating System: ...
status_code

Status of the Tomcat Manager command from the first line of text.

The preferred way to check for success is to use the ok() method, because it checks for http errors as well as tomcat errors. However, if you want specific access to the status of the tomcat command, use this method.

The status codes are enumerated in StatusCode.

>>> import tomcatmanager as tm
>>> tomcat = getfixture("tomcat")
>>> r = tomcat.server_info()
>>> r.status_code == tm.StatusCode.OK
True
status_message

The message on the first line of the response from the Tomcat Server.

result

The text of the response from the Tomcat server, without the first line (which contains the status code and message).

property ok
Returns:

True if the request completed with no errors.

For this property to return True:

  • The HTTP request must return a status code of 200 OK

  • The first line of the response from the Tomcat Manager web application must begin with OK.

raise_for_status()

Raise exceptions for server errors.

First this method calls requests.Response.raise_for_status() which raises exceptions if a 4xx or 5xx response is received from the server.

If that doesn’t raise anything, then it raises a TomcatError if there is not an OK response from the first line of text back from the Tomcat Manager web app.

property response: Response

The server’s response to an HTTP request.

TomcatManager uses the excellent Requests package for HTTP communication. This property returns the requests.Response object which contains the server’s response to the HTTP request.

Of particular use is requests.Response.text which contains the content of the response in unicode. If you want raw access to the content returned by the Tomcat Server, this is where you can get it.