urequests
-
urequests takes 20-30s to throw an OSError if it doesn't get a response. We can't figure out where this timeout comes from. There is no timeout in the original requests library
def request(method, url, data=None, json=None, headers={}, stream=None): try: proto, dummy, host, path = url.split("/", 3) except ValueError: proto, dummy, host = url.split("/", 2) path = "" if proto == "http:": port = 80 elif proto == "https:": import ussl port = 443 else: raise ValueError("Unsupported protocol: " + proto) if ":" in host: host, port = host.split(":", 1) port = int(port) ai = usocket.getaddrinfo(host, port) ai = ai[0] s = usocket.socket(ai[0], ai[1], ai[2])
We thought we'd try to add a shorter timeout following https://docs.python.org/3/library/socket.html#socket.getaddrinfo
def request(method, url, data=None, json=None, headers={}, stream=None, timeout=5): try: proto, dummy, host, path = url.split("/", 3) except ValueError: proto, dummy, host = url.split("/", 2) path = "" if proto == "http:": port = 80 elif proto == "https:": import ussl port = 443 else: raise ValueError("Unsupported protocol: " + proto) if ":" in host: host, port = host.split(":", 1) port = int(port) s = usocket.socket(2,1,0) if timeout is not None: assert hasattr(usocket.socket, 'settimeout'), 'Socket does not support timeout' s.settimeout(timeout) ai = usocket.getaddrinfo(host, port) ai = ai[0]
but it's not giving the 5s timeout we'd like. Can anyone see a way forward with this?