import socket, urllib.request, json s = socket.socket(); s.settimeout(3) try: s.connect(("127.0.0.1", 8000)); print("PORT_OPEN") except Exception as e: print("PORT_CLOSED", repr(e)) finally: s.close() try: r = urllib.request.urlopen("http://127.0.0.1:8000/v1/models", timeout=5) print("MODELS", json.loads(r.read())["data"][0]["id"]) except Exception as e: print("NO_API", repr(e))