|
1 | 1 | import pprint |
| 2 | +from datetime import datetime |
2 | 3 |
|
3 | | -from .constants import HostPrograms, Results, Ports, ServerCommands |
| 4 | +from .constants import HostPrograms, Results, Ports, ServerCommands, Errors |
4 | 5 | import requests |
5 | 6 |
|
6 | 7 | try: |
@@ -91,7 +92,7 @@ def is_host_online(self): |
91 | 92 | :return: *bool* |
92 | 93 | """ |
93 | 94 | response = self.execute("is_online", {}) |
94 | | - return response.get(Results.return_value) |
| 95 | + return response.get(Results.return_value) is True |
95 | 96 |
|
96 | 97 |
|
97 | 98 | def execute(self, command, parameters={}, timeout=0): |
@@ -127,7 +128,21 @@ def execute(self, command, parameters={}, timeout=0): |
127 | 128 |
|
128 | 129 | url = "http://%s:%s" % (self.host_address, self.port) |
129 | 130 | payload = self.__create_payload(command, parameters) |
130 | | - response = requests.post(url, json=payload, timeout=timeout).json() |
| 131 | + |
| 132 | + |
| 133 | + # set the response dictionary to be NO_RESPONSE |
| 134 | + response = { |
| 135 | + Results.time: datetime.now().strftime("%H:%M:%S"), |
| 136 | + Results.success: False, |
| 137 | + Results.return_value: Errors.NO_RESPONSE, |
| 138 | + Results.command: command |
| 139 | + } |
| 140 | + |
| 141 | + try: |
| 142 | + # the response |
| 143 | + response = requests.post(url, json=payload, timeout=timeout).json() |
| 144 | + except requests.exceptions.ConnectionError as err: |
| 145 | + response[Results.return_value] = "\n".join([Errors.CANT_REACH_SERVER, str(err)]) |
131 | 146 |
|
132 | 147 | if self.echo_payload(): |
133 | 148 | pprint.pprint(payload) |
@@ -235,7 +250,7 @@ def execute(self, command, parameters={}, timeout=0, function=True, property=Fal |
235 | 250 | try: |
236 | 251 | response = requests.put(url, json=payload, headers=self.__headers, timeout=timeout).json() |
237 | 252 | except requests.exceptions.ConnectionError: |
238 | | - response = {"ReturnValue": False} |
| 253 | + response = {Results.return_value: Errors.CANT_REACH_SERVER} |
239 | 254 |
|
240 | 255 | try: |
241 | 256 | # UE 4.26: Returning an unreal.Array() that's not empty crashes the editor |
|
0 commit comments