TomcatManagerResponse¶
-
class
tomcatmanager.models.
TomcatManagerResponse
(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(r.server_info.os_name) ... else: ... print('Error: {}'.format(r.status_message)) ... except Exception as err: ... # handle exception ... pass Linux
-
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 Server must begin with
OK
.
- The HTTP request must return a status code of
-
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 anOK
response from the first line of text back from the Tomcat Manager web app.
-
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.There are three status codes:
OK
FAIL
NOTFOUND
tomcatmanager.status_codes
is a dictionary which makes it easy to check this code against known values. It also has attributes with friendly names, as shown here:>>> import tomcatmanager as tm >>> tomcat = getfixture('tomcat') >>> r = tomcat.server_info() >>> r.status_code == tm.status_codes.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).
-
response
¶ The server’s response to an HTTP request.
TomcatManager
uses the excellent Requests package for HTTP communication. This property returns therequests.models.Response
object which contains the server’s response to the HTTP request.Of particular use is
requests.models.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.
-