diff options
| -rwxr-xr-x | agent-lamp | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -138,11 +138,15 @@ def coap(method, url, ident, key, payload=None): if payload is not None: cmd += ["-e", json.dumps(payload, separators=(",", ":"))] try: - out = subprocess.run(cmd + [url], capture_output=True, text=True, - timeout=TIMEOUT + 2, check=True).stdout + done = subprocess.run(cmd + [url], capture_output=True, text=True, + timeout=TIMEOUT + 2) except (subprocess.SubprocessError, OSError): return None - return out.strip() + # coap-client exits 0 on a 4.xx/5.xx response and prints the code on + # stderr only (verified against the gateway: "4.04 Not Found"). + if done.returncode or done.stderr.lstrip()[:2] in ("4.", "5."): + return None + return done.stdout.strip() def put(url, auth, state): |
